【发布时间】:2015-06-29 19:45:56
【问题描述】:
我有以下实现。每个视图都有动画,但我的问题是所有动画都运行,无论可见或不可见。我只希望当前看到(活动)的视图动画作品,其他视图动画被禁用,除非用户滚动它。
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view{
if (view == nil){
if(index==0)
{
view=[[UIImageView alloc]initWithFrame:CGRectMake(30, 30, 600, 600)];
((UIImageView *)view).animationImages=[NSArray arrayWithObjects:[UIImage imageNamed:@"Walking-1.png"],
[UIImage imageNamed:@"Walking-2.png"],
[UIImage imageNamed:@"Walking-3.png"],
[UIImage imageNamed:@"Walking-4.png"],
[UIImage imageNamed:@"Walking-5.png"],nil];
((UIImageView *)view).animationDuration = 1.5;
[((UIImageView *)view) startAnimating];
}
else if(index==1)
{
view=[[UIImageView alloc]initWithFrame:CGRectMake(30, 30, 600, 600)];
((UIImageView *)view).animationImages=[NSArray arrayWithObjects:[UIImage imageNamed:@"Biking-1.png"],
[UIImage imageNamed:@"Biking-2.png"],
[UIImage imageNamed:@"Biking-3.png"],
[UIImage imageNamed:@"Biking-4.png"],
[UIImage imageNamed:@"Biking-5.png"],nil];
((UIImageView *)view).animationDuration = 1.5;
[((UIImageView *)view) startAnimating];
}
view.contentMode = UIViewContentModeCenter;
[view.layer setMasksToBounds:YES];
}
return view;
}
【问题讨论】: