点击按钮,我在当前视图上放置了透明视图。对于覆盖整个屏幕(包括导航栏)的透明视图,我编码如下:
[AppDelegate.window.rootViewController.view addSubview:coverView];
在按钮点击操作中,我放了一些动画代码。
现在,在透明视图中单击按钮,我已经使用以下代码执行滑动过渡效果:
CATransition *animation = [CATransition animation];
[animation setDuration:0.8];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromLeft];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[TransparentView.view layer] addAnimation:animation forKey:nil];
[TransparentView removefromSuperview];
我需要透明视图向左/右滑动(换句话说......从视图中移除TransparentView),MainView应该像以前一样显示。
但它不起作用.. 有人可以帮忙吗?
答案 0 :(得分:1)
arturdev部分正确!!他现在在做的是 - - >从左到右添加CATransition动画0.8秒,之后视图仍然存在。 - >然后从superview中删除它。
而不是那样,通过改变它的框架来隐藏transparentView(这里我用框架宽度替换它的x坐标)。然后添加转换。
[coverView setFrame:CGRectMake([coverView frame].size.width, 0, coverView.frame.size.width, coverView.frame.size.height)];
[CATransaction begin];
CATransition *animation = [CATransition animation];
[CATransaction setCompletionBlock:^{
[coverView removeFromSuperview];
}];
[animation setDuration:0.8];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromLeft];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[coverView layer] addAnimation:animation forKey:nil];
[CATransaction commit];
答案 1 :(得分:0)
[CATransaction begin];
CATransition *animation = [CATransition animation];
[CATransaction setCompletionBlock:^{
[TransparentView removefromSuperview];
}];
[animation setDuration:0.8];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromLeft];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[TransparentView.view layer] addAnimation:animation forKey:nil];
[CATransaction commit];