我在 UIPageController 子类的页面上的图像之间进行交叉溶解。在应用过渡时可以翻页。有时,正在翻页的页面会在翻页过程中变得透明,直到转换完成。
在下面的代码中,Page 类是 UIViewController 的子类,其视图具有 UIImageView 子视图。PageController 是我的 UIPageViewController 子类。
@implementation PageController : UIPageViewController
- (void)crossfadeToImage:(UIImage *)image
{
for (int i = 0; i < self.pages.count; i++) {
Page *page = self.pages[i]; // Pages fed to page controller in delegate
[UIView transitionWithView:page.view duration:duration options:UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionCurveEaseInOut animations:^{
page.image = image;
} completion:nil];
}
}
页面代码如下:
// HEADER
@interface Page : UIViewController
@property (strong, nonatomic) UIImage *image;
- (instancetype)initWithPageFrameSize:(CGSize)size image:(UIImage *)image;
@end
// IMPLEMENTATION
@implementation Page
- (void)loadView
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, _pageFrameSize.width, _pageFrameSize.height)];
self.view = view;
}
- (UIImage *)image
{
return _imageView.image;
}
- (void)setImage:(UIImage *)image
{
if (!_imageView) {
_imageView = [[UIImageView alloc] initWithImage:image];
_imageView.frame = self.view.bounds;
[self.view addSubview:_imageView];
} else {
_imageView.image = image;
}
}
@end
我猜交叉淡入淡出和页面卷曲动画以一种奇怪的方式堆叠。关于如何防止这种“消失的页面”副作用的任何想法?