gpt4 book ai didi

iOS设置带动画的UIImage

转载 作者:行者123 更新时间:2023-11-28 18:21:26 25 4
gpt4 key购买 nike

我正在尝试使用替代图像设置 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com