- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试拼接图像,然后像这样过渡到下一个图像?关于从哪里开始的任何建议?是否可以将图像拼接成小块并使用 UIView 动画对其进行动画处理?这是一个 sample .
编辑:
'#define DESIRED_WIDTH 40
'#define DESIRED_HEIGHT 60
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage *bigImage = [UIImage imageNamed:@"background_for_Manager_App.png"];
CGRect frame = CGRectMake(0.0, 0.0, DESIRED_WIDTH, DESIRED_HEIGHT);
int widthCount = (bigImage.size.width / DESIRED_WIDTH);
int heightCount = (bigImage.size.height / DESIRED_HEIGHT);
NSLog(@"height width %i %i",heightCount,widthCount);
for (int i = 0; i <heightCount; i++) {
for (int j = 0; j < widthCount; j++) {
UIImage *piece = [self imageCroppedWithRect:frame];
UIImageView *view = [[UIImageView alloc] initWithImage:piece];
view.frame = frame;
[self.view addSubview:view];
frame.origin.x += frame.size.width;
NSLog(@"x value %f",frame.origin.x);
}
frame.origin.x = 0.0;
frame.origin.y += frame.size.height;
NSLog(@"y value %f",frame.origin.y);
}
//[UIView beginAnimations:nil context:12 // Do any additional setup after loading the view, typically from a nib.
}
- (UIImage *)imageCroppedWithRect:(CGRect)rect
{
CGFloat scale = [UIImage imageNamed:@"background_for_Manager_App.png"].scale;
NSLog(@"scale value%f",scale);
if (scale > 1.0f)
{ // this is for Retina display capability
rect = CGRectMake(rect.origin.x * scale,
rect.origin.y * scale,
rect.size.width * scale,
rect.size.height * scale);
}
CGImageRef imageRef = CGImageCreateWithImageInRect([UIImage imageNamed:@"background_for_Manager_App.png"].CGImage, rect);
UIImage *result = [UIImage imageWithCGImage:imageRef scale:scale orientation:self.splicedImageView.image.imageOrientation];
CGImageRelease(imageRef);
return result;
}
最佳答案
使用此代码进行裁剪(最好将其添加为 UIImage
类别):
- (UIImage *)imageCroppedWithRect:(CGRect)rect
{
if (self.scale > 1.0f) { // this is for Retina display capability
rect = CGRectMake(rect.origin.x * self.scale,
rect.origin.y * self.scale,
rect.size.width * self.scale,
rect.size.height * self.scale);
}
CGImageRef imageRef = CGImageCreateWithImageInRect(self.CGImage, rect);
UIImage *result = [UIImage imageWithCGImage:imageRef scale:self.scale orientation:self.imageOrientation];
CGImageRelease(imageRef);
return result;
}
使用方法:您应该使用此代码为 UIImage
创建一个类别。然后加载图像并将其切成小块:
UIImage *bigImage = [UIImage imageNamed:@"big_image"];
CGRect frame = CGRectMake(0.0, 0.0, DESIRED_WIDTH, DESIRED_HEIGHT);
for (int i = 0; i < bigImage.size.height / DESIRED_HEIGHT; i++) {
for (int j = 0; i < bigImage.size.width / DESIRED_WIDTH; j++) {
UIImage *piece = [bigImage imageCroppedWithRect:frame];
UIImageView *view = [[UIImageView alloc] initWithImage:piece];
view.frame = frame;
[self.view addSubview:view];
[view release];
frame.origin.x += frame.size.width;
}
frame.origin.x = 0.0;
frame.origin.y += frame.size.height;
}
只需将您的图像切成小块,然后创建适当数量的 UIImageView
对象,并将它们按正确的顺序放置在您的 View 中。现在您可以根据需要为它们制作动画。
另请注意,DESIRED_WIDTH 和 DESIRED_HEIGHT 必须无余地分割图像的边。
对于视频中的动画,您应该使用 UIViewAnimationOptionTransitionFlipFromLeft
选项:
[UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
// hide your image here
} completion:nil];
关于ios - 图像拼接成带有动画的瓦片 - iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12292431/
.splice() 方法的基本问题,以及如何最好地从数组中删除元素。 我想使用 .splice() 从数组中删除一个项目,但是当我这样做时,我希望返回原始数组 减去 删除的元素。 .splice()
我正在过滤同位素库。单击按钮会添加到称为过滤器的数组中。这是正常工作的,但是当用户单击事件按钮时,我希望从数组中删除过滤的类别。由于某种原因,事实并非如此。 这是特定的代码: if($(this).h
几个月前,我将一个 Subversion 存储库转换为 Mercurial,结果在我的修订历史中留下了两个毫无意义的空白。我试图弄清楚我是否可以拼接间隙,但我一直无法让工具精确地完成我想要的。 在项目
我制作简单的射击游戏,但有一个问题(有时): GIF Game problem 3颗子弹被移除(但只有一颗子弹相撞)。子弹和敌人(蓝色方 block )位于一个数组中(var objects = []
假设我们在 JavaScript 中有两个数组,[3,4,7] 和 [5,6]。 在不排序或使用 .apply 的情况下,将 [5,6] 插入索引 2 处的 [3,4,7] 的最佳方式是什么实现结果数
我试图在从数组中删除项目时添加纸质警报对话框,但我似乎无法理解这是如何工作的。 我现在可以使用以下功能,无需对话框: _delete(e) { var index = this.t
我正在尝试使用 splice() 从 jQuery 对象中删除元素. 但是,最终发生的情况是所有其他项目都被删除。我假设这是由于使用 splice 重新索引造成的。 我要淡入每个 所以我需要从顶部开始
这是我尝试从数组中动态删除一个值的尝试 $('.btn-remove').click(function() { var players = ["compare","13076","13075"
我正在考虑在 Visual Studio 2008 上使用 OpenCV 2.3.1 实时拼接来自 2 个或更多(目前可能是 3 或 4 个)摄像头的图像。 但是,我很好奇它是如何完成的。 最近研究了
我在将两个数组拼接在一起时遇到问题。假设我有两个数组: a = array([1,2,3]) b = array([4,5,6]) 当我执行 vstack((a,b)) 时,我得到了 [[1,2,3]
我拼接 css 文件以提高性能。 现在我想包含一个 minify 函数,如下所示。我该如何合并它? function minify( $css ) { $css = preg_replace(
我有两个 matlab 向量。第一个有 N 个元素,另一个有 k*N。我知道 k 是什么,我想拼接列表,使第一个向量中的每个元素出现在下一个向量中相应的 k 元素之前。例如: k = 3 x = [1
我有以下上下文: https://jsfiddle.net/eqntaqbt/2/ obj.forEach(function(user, index){ var userName = user
假设你有一个像这样的数组: var arr= [{id:121, v:'a'}, {id:232, 'b'}]; 你需要找到 id: 232 并删除它,所以你可以这样做: for (var i = a
似乎是通过 建立报价语法非常低效。例如创建一个整数列表 let q1 = List.foldBack (fun n acc -> ) [1..100000] Real: 00:00:05.714,
我正在为一家希望为其用户创建服务的公司开发应用程序。该公司目前提供时长约为 1.5 小时的视频,他们想要集成的服务是让用户能够“录制”这个较大视频的剪辑,以创建本质上的精彩片段。此服务的最终结果将是
splice 当 OFFSET 在数组中但 LENGTH 的末尾超过数组末尾时,是否可以? 最佳答案 易于尝试。 $ perl -wE' my @a = "a".."e"; my @b =
以前从未使用过 Tkinter,我不太确定如何使用它或它是如何工作的。 Windows IDLE Shell。 import time from tkinter import * input("Pre
这里是 Javascript 新手 -- 我有以下数组: var group = ({ one: value1, two: value2, three:
我的屏幕上打印了以下行: Would you like to pay €xx to POS_ID Latte X 1....€2.50-Salad X 1....€4.00-Wrap X 1..
我是一名优秀的程序员,十分优秀!