CATransition black color issue when push right to left
Asked Answered
G

2

15

May be this types of issue occurred with many developer, I also tried to find on Google but there is no luck to solve my problem.

In my app rootViewController set on window dynamically, I mean user can change root view at run time application. So first I am removing current rootViewController from UIWindow and then I set new rootViewController on UIWindow with specific animation. This animation done by CATransition with transition.type = kCATransitionPush;.
My app working very well except animation of new rootViewController. As above I said that I used kCATransitionPush with CATransition

EDITED: Below is my code:

-(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];
}

I also tried to set clearColor and whiteColor of background of UIWindow. But not working.

My Problem is : While animation is process (right to left) I am getting black shadow. So anybody can help me to hide this black shadow? Please give you golden suggestion.

Thanks.

Gereld answered 31/7, 2014 at 6:55 Comment(7)
Please show the code you use to animate.Upu
Set animation duration to 0. [animation setDuration:0.0]; I knows this is not better way, but we can't remove that black shadow.Remind
Other questions/answers about root view controller animation seem to use a different approach. Have you tried those? #8054332Upu
@YogeshSuthar - Then how can I show my animation ??Gereld
@Upu - I checked it but there is no animation like push right to left. Its all about flip or fade :(Gereld
ok.. stupid answer... but have you tried to set the color of the LAYER owing the animation to clear?Katherinakatherine
self.window.layer.backgroundColor = [[UIColor clearColor] CGColor]Katherinakatherine
T
4

Add in the delegate (didFinishLaunchingWithOptions method) these two lines :

self.window.backgroundColor = [UIColor whiteColor];
self.window.tintColor = [UIColor whiteColor];
Tiu answered 1/4, 2015 at 7:53 Comment(1)
I found that setting the tintColor was unnecessary and had the unwanted side effect of changing my tab view controllers tint too.Schaub
B
0

I was having same requirement, I have 3 images of full screen size at splash screen which should slide from right to left. But used of CATransition doesn't solve the issue. So I have used scrollview with paging. Added 3 images in scrollview and then start animation.

- (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];

}

This(startAnimation) method scrolled scrollView upto the width of image, on completion of first image animation, I have started second image animation which scrolled to the edge of scrollview width.

-(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

                                          }];


                     }];

}
Berget answered 10/3, 2017 at 11:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.