Ios CATTransition从右向左推时出现黑色问题
可能是这种类型的问题发生在许多开发者身上,我也尝试在谷歌上查找,但没有运气解决我的问题 在我的应用程序Ios CATTransition从右向左推时出现黑色问题,ios,objective-c,cocoa-touch,catransition,Ios,Objective C,Cocoa Touch,Catransition,可能是这种类型的问题发生在许多开发者身上,我也尝试在谷歌上查找,但没有运气解决我的问题 在我的应用程序rootViewController中,我的意思是用户可以在运行时更改应用程序的根视图。因此,首先我要从UIWindow中删除当前rootViewController,然后用特定动画在UIWindow上设置新的rootViewController。 此动画由cattransition和transition.type=kCATransitionPush完成 除了新的rootViewControll
rootViewController
中,我的意思是用户可以在运行时更改应用程序的根视图。因此,首先我要从UIWindow
中删除当前rootViewController
,然后用特定动画在UIWindow
上设置新的rootViewController
。
此动画由cattransition
和transition.type=kCATransitionPush完成代码>
除了新的rootViewController
的动画外,我的应用程序运行得很好。如上所述,我使用了kCATransitionPush
和cattransition
编辑:
下面是我的代码:
-(void) changeRootViewController
{
for(UIView *subViews in self.window.rootViewController.view.subviews)
[subViews removeFromSuperview];
[self.window.rootViewController.view removeFromSuperview];
self.window.rootViewController.view = nil;
[self.window.rootViewController removeFromParentViewController];
MainRootViewController *mainRootVC = [[MainRootViewController alloc] init];
CATransition *animation = [CATransition animation];
[animation setDuration:0.4];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
animation.fillMode = kCAFillModeForwards;
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
self.window.rootViewController = mainRootVC;
[[self.window layer] addAnimation:animation forKey:nil];
}
我还尝试设置ui窗口背景的clearColor
和whiteColor
。
但不起作用
我的问题是:当动画正在处理时(从右到左),我得到了黑色阴影。有人能帮我隐藏这个黑影吗?请给你一个很好的建议
谢谢。添加代理(didFinishLaunchingWithOptions方法)这两行:
self.window.backgroundColor = [UIColor whiteColor];
self.window.tintColor = [UIColor whiteColor];
我有相同的要求,我有3个全屏大小的启动屏幕应该从右向左滑动的图像。但是使用cattransition并不能解决这个问题。所以我使用了scrollview和分页。在scrollview中添加3个图像,然后启动动画
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
size = [UIScreen mainScreen].bounds.size;
imageArray = [[NSMutableArray alloc] init];
[imageArray addObject:[UIImage imageNamed:@"splashScreen1.png"]];
[imageArray addObject:[UIImage imageNamed:@"splashScreen2.png"]];
[imageArray addObject:[UIImage imageNamed:@"splashScreen3.png"]];
self.splashScrollView.frame = CGRectMake(0,0,size.width,size.height);
self.splashScrollView.contentSize = CGSizeMake(size.width * imageArray.count, size.height);
self.splashScrollView.pagingEnabled = YES;
CGFloat xPos = 0.0;
for (UIImage *image in imageArray) {
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = CGRectMake(xPos, 0.0, size.width, size.height);
[self.splashScrollView addSubview:imageView];
xPos += size.width;
}
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(startAnimation) userInfo:nil repeats:NO];
}
这种(startAnimation)方法将scrollView滚动到图像的宽度,在完成第一个图像动画后,我启动了第二个图像动画,该动画滚动到scrollView宽度的边缘
-(void) startAnimation{
[UIView animateWithDuration:2.0
animations:^{
self.splashScrollView.contentOffset = CGPointMake(size.width, 0.0);
} completion:^(BOOL finished) {
[UIView animateWithDuration:2.0
animations:^{
self.splashScrollView.contentOffset = CGPointMake((self.splashScrollView.contentSize.width - CGRectGetWidth(self.splashScrollView.frame)), 0.0);
} completion:^(BOOL finished) {
//At animation end go to login
}];
}];
}
请显示用于设置动画的代码。将动画持续时间设置为0<代码>[动画设置持续时间:0.0]代码>我知道这不是更好的方法,但我们无法移除黑色阴影。关于根视图控制器动画的其他问题/答案似乎使用了不同的方法。你试过那些吗@YogeshSuthar-那么我如何显示我的动画???@Droppy-我检查了它,但没有像从右向左推这样的动画。这一切都是关于翻转或淡入:(我发现设置淡入淡出淡出淡出淡出淡出淡出淡出淡出淡出淡出淡出淡出淡出淡出淡出淡出淡出淡出淡出淡出淡出淡出淡出淡出淡出淡出淡出淡出淡出淡出淡出淡出淡出淡出淡。