我用下面的代码交换意见如何编写Objective-C的功能
- (void)loading2menu{
[UIView beginAnimations:@"Loading2Menu" context:nil];
[UIView setAnimationDuration:1.25];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
if (self.menuViewController.view.superview == nil)
{
if (self.menuViewController == nil)
{
MenuViewController *menuController =
[[MenuViewController alloc] initWithNibName:@"MenuView"
bundle:nil];
self.menuViewController = menuController;
[menuController release];
}
[UIView setAnimationTransition:
UIViewAnimationTransitionCurlUp
forView:self.view cache:YES];
[loadingViewController viewWillAppear:YES];
[menuViewController viewWillDisappear:YES];
[loadingViewController.view removeFromSuperview];
[self.view insertSubview:menuViewController.view atIndex:0];
[menuViewController viewDidDisappear:YES];
[loadingViewController viewDidAppear:YES];
}
else
{
if (self.loadingViewController == nil)
{
LoadingViewController *loadingController =
[[LoadingViewController alloc] initWithNibName:@"LoadingView"
bundle:nil];
self.loadingViewController = loadingController;
[loadingController release];
}
[UIView setAnimationTransition:
UIViewAnimationTransitionCurlDown
forView:self.view cache:YES];
[menuViewController viewWillAppear:YES];
[loadingViewController viewWillDisappear:YES];
[menuViewController.view removeFromSuperview];
[self.view insertSubview:loadingViewController.view atIndex:0];
[loadingViewController viewDidDisappear:YES];
[menuViewController viewDidAppear:YES];
}
[UIView commitAnimations];
}
我认为这是太多的代码,并且如果我必须切换更多的意见,我必须多写这样的代码,它浪费时间,是不是要做到这一点的最好办法,所以我写做同样的事情
- (void)switchtheviews:(UIViewController*)coming over:(UIViewController*)going {
[UIView beginAnimations:@"frame" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:viewController.view cache:YES];
[coming viewWillAppear:YES];
[going viewWillDisappear:YES];
[going.view removeFromSuperview];
[viewController.view insertSubview:coming.view atIndex:0];
[going viewDidDisappear:YES];
[coming viewDidAppear:YES];
[UIView commitAnimations];
}
这么一个功能,我怎么能调用这个函数?如果我使用旧的,我可以用
[[MyAppsAppDelegate App].switchViewController loading2menu];
但这种新的,我应该怎么写调用新的功能?感谢
你能澄清你想要做什么吗?你只是想用另一个视图替换一个视图? – 2011-06-14 17:57:08
是的,我只是想通过减少代码来替换一个视图。我也想知道如何在代码中调用函数“switchtheviews”,谢谢 – matt 2011-06-14 18:05:04