Ezequiel Ing
Ezequiel Ing

Reputation: 130

viewController no full screen

anyone know how to implement something like a viewController no full screen just like when we tap in search in the iPhone ? I want that when the user make an swipe up a viewController (half height) be showed. No segue !! I would like that the old view controller be showed at the same time. Thanks in advance

Upvotes: 0

Views: 506

Answers (3)

Paras Joshi
Paras Joshi

Reputation: 20551

I Add this type of functionality for whole project, i add the QRView in window so user swip up the view from any view of project...

See the Example of my code..

Just set the UISwipeGestureRecognizer to your second view which you want to present like bellow...

 CATransition *animation = [CATransition animation];
    [animation setDelegate:self];   
    [animation setType:kCATransitionFade];
    [animation setDuration:0.5];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:
                                  kCAMediaTimingFunctionEaseInEaseOut]];
    [[self.view layer] addAnimation:animation forKey:kAnimationKey];
    UISwipeGestureRecognizer *swipeGesture = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(addCustomBottomBar)] autorelease];
    swipeGesture.numberOfTouchesRequired = 1;
    swipeGesture.direction = (UISwipeGestureRecognizerDirectionDown);
    [yourViewController.view addGestureRecognizer:swipeGesture];/// use your view name here, its depends on your requirement
    UISwipeGestureRecognizer *swipeGestureTop = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(addCustomBottomBar)] autorelease];
    swipeGestureTop.numberOfTouchesRequired = 1;
    swipeGestureTop.direction = (UISwipeGestureRecognizerDirectionUp);

    [yourViewController.view addGestureRecognizer:swipeGestureTop];

and this bellow method called when you swipe up view...

Also just add one BOOL variable with name isViewPop and set it to NO in your viewDidLoad: method ..

-(void)addCustomBottomBar{

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.window cache:YES];

    if (isqrcodepop) {
        isViewPop=NO;

        yourViewController.view.frame=CGRectMake(0, 430, 320, 70);
    }
    else{
        isViewPop=YES;

        yourViewController.view.frame=CGRectMake(0, 210, 320, 270);
        [self.view bringSubviewToFront:yourViewController.view];
    }
    [UIView commitAnimations];
}

i hope this answer helpful for you...

Upvotes: 1

RyanG
RyanG

Reputation: 4503

If it is something simple I would add a UIView to your UIViewController just below the bottom-- then when you hit 'Search' or whatever, animate that UIView up in view with an animation block:

- (IBAction)btnTouch:(id)sender
{
        [UIView animateWithDuration:0.3
                              delay:0.0
                            options: UIViewAnimationCurveEaseInOut
                         animations:^{

                              //bring searchView up
                             _searchView.transform = CGAffineTransformMakeTranslation(0, -80);

                         }
                         completion:^(BOOL finished){

                         }

         ];
}

Then when you are done, push the view back to its origin by using the same animation block with this line instead:

_searchView.transform = CGAffineTransformMakeTranslation(0, 0);

Upvotes: 1

Ege Akpinar
Ege Akpinar

Reputation: 3286

You could have the background view controller [self presentViewController:vc animated:YES completion:nil]; and set your front view controller's frame to half of the screen. This way, since bottom half of the front view is transparent, your background view controller will still be visible

Upvotes: 0

Related Questions