与其创建两个视图UIImageViews,不如简单地更改image一个视图的视图,这是合乎逻辑的。如果这样做,是否会在两个图像之间使淡入淡出/交叉消失而不是立即切换?
UIImageViews
image
编辑:下面的@algal有更好的解决方案。
另一种方法是使用预定义的CAAnimation过渡:
CATransition *transition = [CATransition animation]; transition.duration = 0.25; transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; transition.type = kCATransitionFade; transition.delegate = self; [self.view.layer addAnimation:transition forKey:nil]; view1.hidden = YES; view2.hidden = NO;
请参阅Apple的View Transitions示例项目:https : //developer.apple.com/library/content/samplecode/ViewTransitions/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007411