joa*_*kim 15 animation objective-c uiimageview tintcolor ios
tintColor是一个救生员,它需要应用主题到一个全新的(简单)级别.
//the life saving bit is the new UIImageRenderingModeAlwaysTemplate mode of UIImage
UIImage *templateImage = [[UIImage imageNamed:@"myTemplateImage"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
imageView.image = templateImage;
//set the desired tintColor
imageView.tintColor = color;
Run Code Online (Sandbox Code Playgroud)
上面的代码将根据UIImageview的色调颜色"绘制"图像的非透明部分,这非常酷.不需要像这样简单的核心图形.
我面临的问题是动画.
继续上述代码:
//The array with the names of the images we want to animate
NSArray *imageNames = @[@"1",@"2"@"3"@"4"@"5"];
//The array with the actual images
NSMutableArray *images = [NSMutableArray new];
for (int i = 0; i < imageNames.count; i++)
{
[images addObject:[[UIImage imageNamed:[imageNames objectAtIndex:i]] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];
}
//We set the animation images of the UIImageView to the images in the array
imageView.animationImages = images;
//and start animating the animation
[imageView startAnimating];
Run Code Online (Sandbox Code Playgroud)
动画正确执行但图像使用其原始颜色(即gfx编辑应用程序中使用的颜色)而不是UIImageView的tintColor.
我将尝试自己执行动画(通过在顶部做一些事情,比如循环遍历图像并使用NSTimer延迟设置UIImageView的图像属性,以便人眼可以捕获它).
在这之前,我想问一下UIImageView的tintColor属性是否应该支持我正在尝试用它做什么,即用它来制作动画.
谢谢.
.tintColor 也许可以处理它。我一直使用 NSTimers 作为 UIButton 的 setTitleColor 方法。这是一个例子。
更新:已在 iPhone 5s iOS 7.1 上测试并运行!
- (void)bringToMain:(UIImage *)imageNam {
timer = [NSTimer scheduledTimerWithTimeInterval:.002
target:self
selector:@selector(animateTint)
userInfo:nil
repeats:YES];
}
- (void)animateTint {
asd += 1.0f;
[imageView setTintColor:[UIColor colorWithRed:((asd/100.0f) green:0.0f blue:0.0f alpha:1.0f]];
if (asd == 100) {
asd = 0.0f
[timer invalidate];
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6679 次 |
| 最近记录: |