我想有一个UIViewController
从右侧出现“幻灯片”动画。不像 Push segue,也不像 Facebook 应用程序。我希望新的 ViewController 滑到当前 ViewController 的顶部(而不是将其推开),但只覆盖屏幕的一部分,而让另一部分显示第一个 ViewController。
我尝试过的:我得到的最接近的是通过使用以下内容创建自定义转场:
- (void)perform
{
__block UIViewController *src = (UIViewController *) self.sourceViewController;
__block UIViewController *dst = (UIViewController *) self.destinationViewController;
CATransition* transition = [CATransition animation];
transition.duration = .50;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromRight;
[src.navigationController.view.layer addAnimation:transition forKey:@"SwitchToView1"];
[src.navigationController pushViewController:dst animated:NO];
}
这实现了我想要的动画,但它覆盖了整个第一个 ViewController。我怎样才能让它停在某个点而不覆盖整个事情?
我正在使用故事板,这是我第一次尝试任何类型的新动画。
您可以尝试在源视图控制器中执行此操作,并更改目标(x 轴)的框架,例如:
- (void) perform {
UIViewController *dst = (UIViewController *) self.destinationViewController;
[dst.view setFrame:CGRectMake(160, 0, YOUR_DST_WIDTH, YOUR_DST_HEIGHT)];
//your animation stuff...
[self addChildViewController:dst];
[self.view addSubview:dst.view];
[dst didMoveToParentViewController:self];
}
那应该可以了!
如果没有的话请告诉我...
UPDATE!:
@CaptJak嘿,抱歉,这对你不起作用..我编写了以下代码,它在这里工作没有任何问题..我将它链接到按钮单击..尝试一下并让我知道! (PS:我也添加了动画!)。
ViewController *tlc = [self.storyboard instantiateViewControllerWithIdentifier:@"MainViewController"];
[tlc.view setFrame:CGRectMake(-320, 0, self.view.frame.size.width, self.view.frame.size.height)];
[self addChildViewController:tlc];
[self.view addSubview:tlc.view];
[tlc didMoveToParentViewController:self];
[UIView animateWithDuration:0.3 animations:^{
[tlc.view setFrame:CGRectMake(-160, 0, self.view.frame.size.width, self.view.frame.size.height)];
}];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)