在我的应用程序中,我使用动画进行启动画面。 此动画在延迟5秒后停止。 但是如果用户中断(触摸)动画应该停止,我希望在5秒之前。
对于我写的动画:
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Array to hold jpg images
imageArray = [[NSMutableArray alloc] initWithCapacity:IMAGE_COUNT];
// Build array of images, cycling through image names
imageArray = [NSMutableArray arrayWithObjects: [UIImage imageNamed:@"f1.jpg"], [UIImage imageNamed:@"f2.jpg"], [UIImage imageNamed:@"f3.jpg"], [UIImage imageNamed:@"f4.jpg"], [UIImage imageNamed:@"f5.jpg"], [UIImage imageNamed:@"f6.jpg"], nil];
// Animated images - centered on screen
animatedImages = [[UIImageView alloc]
initWithFrame:CGRectMake(
(SCREEN_WIDTH / 2) - (IMAGE_WIDTH / 2),
(SCREEN_HEIGHT / 2) - (IMAGE_HEIGHT / 2) + STATUS_BAR_HEIGHT,
IMAGE_WIDTH, IMAGE_HEIGHT)];
animatedImages.animationImages = [NSArray arrayWithArray:imageArray];
// One cycle through all the images takes 1.5 seconds
animatedImages.animationDuration =1;
// Repeat forever
animatedImages.animationRepeatCount = -1;
// Add subview and make window visible
[window addSubview:animatedImages];
[window makeKeyAndVisible];
// Start it up
//animatedImages.startAnimating;
[animatedImages startAnimating];
// Wait 5 seconds, then stop animation
[self performSelector:@selector(stopAnimation) withObject:nil afterDelay:5.0];
}
- (void)stopAnimation
{
[animatedImages stopAnimating];
[window addSubview:viewController.view];
[window makeKeyAndVisible];
}
答案 0 :(得分:1)
没问题
在stopAnimation
方法中调用tochesBegan
方法,就像这样
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
YourAppDelegate *obj=(YourAppDelegate *)[[UIApplication sharedApplication] delegate];
[obj stopAnimation];
}