【发布时间】:2013-10-22 21:43:34
【问题描述】:
我正在为 iPhone 制作一个应用程序,我希望当我触摸一个按钮时,当你从屏幕的顶部到底部触摸时,它会打开一个带有幻灯片效果的视图。该视图与按钮位于同一个 XIB 文件中...提前谢谢
【问题讨论】:
-
你试过什么?
标签: iphone
我正在为 iPhone 制作一个应用程序,我希望当我触摸一个按钮时,当你从屏幕的顶部到底部触摸时,它会打开一个带有幻灯片效果的视图。该视图与按钮位于同一个 XIB 文件中...提前谢谢
【问题讨论】:
标签: iphone
你可以试试这个简单的动画-
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];
【讨论】:
你需要使用下面的代码,你的要求很简单,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 方法中设置此视图控制器的框架,如下所示...
-(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];
}
希望对你有帮助..... :)
【讨论】: