iPhone推视图控制器的左方向
-
11-09-2019 - |
题
我有具有与关于它每一侧上的两个视图的中心视图的应用程序。我想有两个导航栏按钮,左和右这推动了新的导航控制器上从左侧或右侧的视图。
当你改变通过推动使用pushviewController一个新的视图的观点:NavigationController的方法,该视图显示从右侧滑入。如何更改此从左侧滑入?
解决方案
除了使用导航控制器的,我也只是移动视图。
CGRect inFrame = [currentView frame];
CGRect outFrame = firstFrame;
outFrame.origin.x -= inFrame.size.width;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[newView setFrame:inFrame];
currentView setFrame:outFrame];
[UIView commitAnimations];
其他提示
我已经做了改变动画方向时,我们推视图控制器。 你可以在这里改变动画类型的 [动画setSubtype:kCATransitionFromRight]; 强>
ViewController *elementController = [[ViewController alloc] init];
// set the element for the controller
ViewController.element = element;
// push the element view controller onto the navigation stack to display it
CATransition *animation = [CATransition animation];
[[self navigationController] pushViewController:elementController animated:NO];
[animation setDuration:0.45];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
[[elementController.view layer] addAnimation:animation forKey:@"SwitchToView1"];
[elementController release];
我不认为你可以明确地定义UINavigationControllers滑动方向。你也许能够做的是弹出当前视图从导航堆栈以显示前视图,它会在你想要的方式动画。但是,如果你想有不同的视图控制器的出现决定于你当前视图什么,这可能是复杂的。
如果您的工作流程是不是太复杂,你可以拿着在当前视图控制器现有视图控制器的参考。取决于你当前视图什么(例如选择一个表格视图单元格)时,可以更改在现有视图控制器需要的任何数据,然后调用
[self.navigationController popViewController];
或任何正确的方法是(我认为这是非常接近它是如何)。它可以让你向下移动导航堆栈你想要的动画,这工作,如果您的导航堆栈上有意见定数。
要什么里德奥尔森说:必须只钩住一个按钮,启动所述滑动到相同的方法和添加跟踪如果被示出或不视图的BOOL。所有你需要做的是设置正确的起源。
- (IBAction)slideMenuView
{
CGRect inFrame = [self.view frame];
CGRect outFrame = self.view.frame;
if (self.viewisHidden) {
outFrame.origin.x += inFrame.size.width-50;
self.viewisHidden = NO;
} else {
outFrame.origin.x -= inFrame.size.width-50;
self.viewisHidden = YES;
}
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[self.menuView setFrame:inFrame];
[self.view setFrame:outFrame];
[UIView commitAnimations];
}
要得到“尖”类型的按钮就需要使用一个不同的方法。
在AppDelegate中:
UITableViewController *first = [[RootViewController alloc] initWithStyle:UITableViewStylePlain];
UITableViewController *second = [[SomeOtherViewController alloc] initWithStyle:UITableViewStylePlain];
NSArray *stack = [NSArray arrayWithObjects: first, second, nil];
UINavigationController *nav = [[UINavigationController alloc] init];
[nav setViewControllers:stack animated:NO];
可以继承RTLNavigationController:UINavigationController的并覆盖这些功能
- (void) pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
DummyViewController*dvc = [[DummyViewController alloc] init];
[super pushViewController:viewController animated:NO];
[super pushViewController:dvc animated:NO];
[dvc release];
[super popViewControllerAnimated:YES];
}
和
- (UIViewController *)popViewControllerAnimated:(BOOL)animated
{
UIViewController *firstViewController = [super popViewControllerAnimated:NO];
UIViewController *viewController = [super popViewControllerAnimated:NO];
[super pushViewController:viewController animated:animated];
return firstViewController;
}
和在应用程序的代理:
navCon = [[RTLNavigationController alloc] init];
rootViewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
rootViewController.contextDelegate = self;
DummyViewController *dvc = [[DummyViewController alloc]init];
[navCon pushViewController:dvc animated:NO];
[dvc release];
[navCon pushViewController:rootViewController animated:NO];
[self.window addSubview:navCon.view];
推会从左至右和从弹出右至左
不隶属于 StackOverflow