2011-03-10 71 views
0

在我的应用程序中,我使用动画进行启动屏幕。 这个动画在延迟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

你应该重新考虑你的起动程序,反正。应用程序应尽可能快地启动,以便让用户体验“多线程感觉”。一些开发人员花费数天的时间让App开始更快。如果用户第一次看到它,动画可能会很好。经过2或3次创业之后,它可能会很糟糕。 – 2011-03-10 11:20:47

回答

1

不是一个问题

呼叫stopAnimation方法tochesBegan方法这样

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    YourAppDelegate *obj=(YourAppDelegate *)[[UIApplication sharedApplication] delegate]; 
    [obj stopAnimation]; 
} 
+0

好的,我实现了,但控制不会触及touchBegan函数。我在appDelegate中编写所有上面的代码。 – 2011-03-10 11:07:52

+0

见编辑答案。 – Ishu 2011-03-10 11:09:36

+0

但问题是控制不会继续tochesBegan函数。顺便说一句,第一行是怎么回事。 – 2011-03-10 11:14:30