Reputation: 499
I'm making an application for iPhone, and I want that when I touch a button it opens a view with a slide effect when you touch from the top to the bottom of the screen. The view is in the same XIB file as the button...Advance thanks
Upvotes: 0
Views: 1836
Reputation: 20541
you need that use bellow code with your requirement simple with GestureRecognizer
- (void)viewDidLoad
{
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);
[yourDownViewController.view addGestureRecognizer:swipeGesture];
UISwipeGestureRecognizer *swipeGestureTop = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(addCustomBottomBar)] autorelease];
swipeGestureTop.numberOfTouchesRequired = 1;
swipeGestureTop.direction = (UISwipeGestureRecognizerDirectionUp);
[yourUpViewController.view addGestureRecognizer:swipeGestureTop];
}
here you just set frame on of your this viewcontroller in addCustomBottomBar
method like bellow...
-(void)addCustomBottomBar{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.window cache:YES];
yourUpViewController.view.frame=CGRectMake(0, 430, 320, 70);//here you can also switch two ViewWith some flag otherwise create another method for anotherView....
[UIView commitAnimations];
}
2.if you want to Animation with up the ViewController with button Click then use bellow code.....
-(void)btnClicked{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.view cache:YES];
if (yourflag) {
yourViewController.view.frame=CGRectMake(0, 430, 320, 70);
}
else{
yourflag=YES;
yourViewController.view.frame=CGRectMake(0, 210, 320, 270);
[self.view bringSubviewToFront:yourViewController.view];
}
[UIView commitAnimations];
}
hope,this help you..... :)
Upvotes: 0
Reputation: 11839
You can try this simple animation -
UIView *myView = [[UIView alloc] initWithFrame:self.view.frame];
myView.backgroundColor = [UIColor blueColor];
[self.view addSubview:myView];
[myView setFrame:CGRectMake(0, 480, 320, 480)];
[myView setBounds:CGRectMake(0, 0, 320, 480)];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
[myView setFrame:CGRectMake(0, 0, 320, 480)];
[UIView commitAnimations];
Upvotes: 1