Search code examples
iosuiviewxcode7uianimation

How to give sliding animation to a single UIView?


I have one screen, call it video screen where one video is shown with details and comments just like youtube. Now this view is slidable, means whenever user slides the screen, next or previous video comes by changing whole content view.

I am using [UIView transitionWithView] to give it sliding effect. By changing frame of content view, I am doing swiping right code like below.

 [UIView transitionWithView:viewTop duration:0.4
                       options:UIViewAnimationOptionTransitionCrossDissolve
                    animations:^{
                        viewTop.frame = CGRectMake(SCREEN_WIDTH, viewTop.frame.origin.y, viewTop.frame.size.width, viewTop.frame.size.height);
                    }
                    completion:^(BOOL Finished){

                        [self getNextVideoDetail];
                        viewTop.frame = CGRectMake(-SCREEN_WIDTH, viewTop.frame.origin.y, viewTop.frame.size.width, viewTop.frame.size.height);

                        [UIView transitionWithView:viewTop duration:0.3
                                    options:UIViewAnimationOptionTransitionCrossDissolve
                                 animations:^{
                                     viewTop.frame = CGRectMake(0, viewTop.frame.origin.y, viewTop.frame.size.width, viewTop.frame.size.height);
                                 }
                                 completion:nil
                  ];

                    }];

Here, viewTop is my content view. Everything works fine but I want that whenever I slide the screen to left, before the view disappears completely, some part of the view should be shown at the right side. Because the code I wrote above will show white self.view and screen will be blank for some mili seconds.

Is it possible with only one UIView to navigate videos like giving mirror effect?


Solution

  • Use this:

    CATransition *transition = [CATransition animation];
    transition.type = kCATransitionPush;
    transition.subtype = kCATransitionFromLeft;
    transition.duration = 0.4;
    [viewTop.layer addAnimation:transition forKey:nil];