我确信我在这里错过了一些非常容易的东西......
我第一次循环浏览图像时,索引重置并正确递增,但UIView不刷新并保持数组中的最后一个图像显示。 transitionFromView:自动交换子视图,对吧?我是否需要实现完成:选项?
我错过了什么?这是相关的代码:
- (id)initWithFrame:(CGRect)frame
{
NSInteger maxSlides = 12;
self = [super initWithFrame: frame];
if (self) {
//set up an array of images to be used for a flipbook
slides = [[NSMutableArray alloc] initWithCapacity: maxSlides];
for(NSInteger i=0; i<maxSlides; ++i) {
imageView = [[UIImageView alloc] initWithImage:
[UIImage imageNamed:[NSString stringWithFormat: @"muybridge%d.png", i]]];
[slides addObject: imageView];
}
index = 0; //default to first photo.
[self addSubview: [slides objectAtIndex: index]];
}
return self;
}
- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event
{
//output indices for debugging. (yes, they increment properly)
NSLog(@"index = %d", index);
NSLog(@"currentIndex = %d", currentIndex);
NSLog(@"nextIndex = %d", nextIndex);
if (nextIndex <= 10) {
currentIndex = nextIndex;
} else {
currentIndex = 0;
}
nextIndex = currentIndex + 1;
//flipbook - tapping the image transitions to the next image in the array
[UIView transitionFromView: [slides objectAtIndex: currentIndex]
toView: [slides objectAtIndex: nextIndex]
duration: 0
options: UIViewAnimationOptionTransitionCurlUp
completion: NULL
];
}
答案 0 :(得分:0)
根据Apple UIView: transitionFromView: toView:...
的参考资料:
此方法仅修改视图层次结构中的视图。它不会以任何方式修改应用程序的视图控制器。例如,如果使用此方法更改视图控制器显示的根视图,则您有责任相应地更新视图控制器以处理更改。
也许在尝试之后立即调用[yourView setNeedsDisplay]
方法。
答案 1 :(得分:0)
你在缺少的是这个,来自transitionFromView上的文档:toView:...:
fromView 过渡的起始视图。默认情况下,此视图将作为转换的一部分从其超级视图中删除。
所以它是有效的,第一次通过,但只有一个子视图,最后一个,在你看完它们之后仍然存在。查看UIViewAnimationOptionShowHideTransitionViews选项。