我正在为iPhone制作应用程序,我希望当我触摸按钮时,当您从屏幕的顶部触摸到底部时,它会打开一个带有幻灯片效果的视图。视图与按钮位于同一个XIB文件中...提前谢谢
答案 0 :(得分:1)
您可以尝试这个简单的动画 -
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];
答案 1 :(得分:0)
您需要使用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];
}
这里你只需在addCustomBottomBar
方法中设置这个viewcontroller的框架就像下面那样......
-(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.如果你想使用带按钮的ViewController进行动画点击然后使用下面的代码.....
-(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];
}
希望,这有助于你......
:)