Search code examples
iphoneobjective-ciosxcodexcode4

Sliding View From the Left


I am trying to build a app that will have a view hidden unless you pull it from right. For example the Dolphin web browser for iOS has the ability to pull from the right and it will bring up your favorites and some other options. Does anyone know of a way to implement that into a application? Is there some code or tutorials floating around?

Heres the link to the Dolphin iOS App: http://itunes.apple.com/us/app/dolphin-browser-hd/id460812023?mt=8


Solution

    1. Create two views. ViewA & ViewB
    2. ViewA is the view that loads.
    3. Add ViewB to ViewA with ViewB being off the screen so the user cannot see it.
    4. in ViewDidLoad of ViewA add a UISwipeGestureRecognizer so you can be notified of a swipe gesture.
    5. If swipe happens move ViewB into view with a UITransition.

    in viewDidLoad to capture swipe gesture

    UITapGestureRecognizer *swipe = [[UISwipeGestureRecognizerDirectionRight alloc] initWithTarget:self action:@selector(swipeDetected)];
        [viewA addGestureRecognizer:swipe];
        [swipe release];
    
    -(void)swipeDetected {
         //transition viewB into view of user
         [UIView beginAnimations:nil context:NULL];
         [UIView setAnimationDelay:0];
         [UIView setAnimationDuration:0.75];
         CGRect rect5 = CGRectMake(0, 0, 320, 480);
         viewB.frame = rect5;       
         [UIView commitAnimations];
    }