Edv*_*das 34 uinavigationcontroller pushviewcontroller ios7 xcode5
最近我更新了我的xcode项目以使用iOS 7,但我遇到了一个大问题.因为我的整个应用程序只有一个背景图像(UIImageView添加到关键窗口)并且所有视图都是透明的,所以我在推UIViewController时遇到问题,因为推送的视图控制器与之前的视图重叠(你可以在这里看到它:http:/ /grab.by/qp0k).我可以预测这是因为在iOS 7中推送转换已经改变,因为现在它滑动了半个屏幕.也许有人知道如何解决这个问题?
这就是我设置关键窗口的方法
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIImageView *background = [[UIImageView alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
background.image = [UIImage imageNamed:@"background.png"];
UINavigationController *navi = [[UINavigationController alloc]initWithRootViewController:self.viewController];
self.window.rootViewContro??ller = navi;
[self.window makeKeyAndVisible];
Run Code Online (Sandbox Code Playgroud)
之后当用户点击"开始锻炼"按钮时,我会一如既往地推送我的下一个视图:
workoutView *w = [[workoutView alloc]initWithNibName:@"workoutView" bundle:nil];
[self.navigationController pushViewController:w animated:YES];
Run Code Online (Sandbox Code Playgroud)
Ale*_*dre 19
我这样做了
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[self.view setAlpha:0];
}
Run Code Online (Sandbox Code Playgroud)
回来时不要忘记重新设置alpha.
- (void) viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.view setAlpha:1];
}
Run Code Online (Sandbox Code Playgroud)
sno*_*oer 15
我通过实现新UINavigationControllerDelegate方法解决了这个问题animationControllerForOperation.
例如:
- (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
animationControllerForOperation:(UINavigationControllerOperation)operation
fromViewController:(UIViewController *)fromVC
toViewController:(UIViewController *)toVC
{
PushTransition* transition = [PushTransition new];
[transition setNavigationControllerOperation: operation];
return transition;
}
Run Code Online (Sandbox Code Playgroud)
PushTransition是一个实现UIViewControllerAnimatedTransitioning协议的类,以及来自该协议的两个方法transitionDuration和animateTransition.另外,我添加了一个属性来传递操作(告诉我它是推送还是弹出过渡).
只需将用于移动视图的动画代码放入animateTransition,如下所示:
// the containerView is the superview during the animation process.
UIView *container = transitionContext.containerView;
UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIView *fromView = fromVC.view;
UIView *toView = toVC.view;
CGFloat containerWidth = container.frame.size.width;
// Set the needed frames to animate.
CGRect toInitialFrame = [container frame];
CGRect fromDestinationFrame = fromView.frame;
if ([self navigationControllerOperation] == UINavigationControllerOperationPush)
{
toInitialFrame.origin.x = containerWidth;
toView.frame = toInitialFrame;
fromDestinationFrame.origin.x = -containerWidth;
}
else if ([self navigationControllerOperation] == UINavigationControllerOperationPop)
{
toInitialFrame.origin.x = -containerWidth;
toView.frame = toInitialFrame;
fromDestinationFrame.origin.x = containerWidth;
}
// Create a screenshot of the toView.
UIView *move = [toView snapshotViewAfterScreenUpdates:YES];
move.frame = toView.frame;
[container addSubview:move];
[UIView animateWithDuration:TRANSITION_DURATION delay:0
usingSpringWithDamping:1000 initialSpringVelocity:1
options:0 animations:^{
move.frame = container.frame;
fromView.frame = fromDestinationFrame;
}
completion:^(BOOL finished) {
if (![[container subviews] containsObject:toView])
{
[container addSubview:toView];
}
toView.frame = container.frame;
[fromView removeFromSuperview];
[move removeFromSuperview];
[transitionContext completeTransition: YES];
}];
Run Code Online (Sandbox Code Playgroud)
描述它,你可以完成.此外,您可以制作任何您喜欢的推送或流行动画.
我在初始化视图时通过执行此操作来修复它:
self.view.clipsToBounds = YES;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23187 次 |
| 最近记录: |