作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用替代图像设置 UIImageView 的图像。我知道我可以做到 [imageView setImage: image]。但是,当我更改图像时是否可以添加任何溶解效果(动画)?
最佳答案
我之前已经这样做过,这里有一段代码可以帮助您解决问题。这段代码可以很好地解决您上面描述的问题。
-(void)changeImage
{
myImageView.animationImages=[NSArray arrayWithArray:self.yourImageArray];
myImageView.animationDuration=10.0;
myImageView.animationRepeatCount=0;
[myImageView startAnimating];
myImageView.transform = CGAffineTransformMakeRotation(M_PI/2);
[self.view addSubview:myImageView];
//The timers time interval is the imageViews animation duration devided by the number of images in the animationImages array. 20/5 = 4
NSTimer *timer = [NSTimer timerWithTimeInterval:2.0
target:self
selector:@selector(onTimer)
userInfo:nil
repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
[timer fire];
}
//这将淡入和淡出图像。
-(void)onTimer{
[UIView animateWithDuration:2.0 animations:^{
myImageView.alpha = 0.0;
}];
[UIView animateWithDuration:0.5 animations:^{
myImageView.alpha = 1.0;
}];
}
如果你想要交叉溶解,你可以使用这个 UIViewAnimationOptionTransitionCrossDissolve。希望这会对您有所帮助,如果没有,请随时询问。
关于iOS设置带动画的UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19761026/
我是一名优秀的程序员,十分优秀!