我正在为 iPhone 制作一个应用程序,我希望当我触摸一个按钮时,当你从屏幕的顶部到底部触摸时,它会打开一个带有幻灯片效果的视图。该视图与按钮位于同一个 XIB 文件中...提前谢谢
问问题
1817 次
2 回答
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];
于 2012-05-14T10:46:17.083 回答
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
方法在此视图控制器上设置框架...
-(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];
}
希望,这对你有帮助..... :)
于 2012-05-14T10:54:47.043 回答