我的应用程序开头有一个简单的动画。
它在主视图上显示一个 UIView,该 UIView 在启动时在屏幕外显示动画。我只希望它在应用程序启动时制作动画,而不是每次加载主视图时。我的问题是使用我的代码我可以根据需要停止动画,但是它会在加载主视图时恢复到覆盖视图的开始状态。
总而言之,我想将 UIview 设置为离开屏幕的动画,并使其保持在那里,直到应用程序重新启动。非常感谢任何建议
- (void)viewDidLoad
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(performAnimation:) name:UIApplicationDidBecomeActiveNotification object:nil];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
[self setDoorbottom:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (IBAction)alert:(id)sender {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"" delegate:nil cancelButtonTitle: @"Dismiss" otherButtonTitles: nil];
[alert show];
}
- (void)performAnimation:(NSNotification *)aNotification {
// Animation code.
CGRect doorbottomFrame = doorbottom.frame;
doorbottomFrame.origin.y = self.view.bounds.size.height;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:0.3];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
doorbottom.frame = doorbottomFrame;
[UIView commitAnimations];
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"Air", CFSTR
("wav"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID (soundFileURLRef, &soundID);
AudioServicesPlaySystemSound (soundID);
}
@end