我是新的iphone開發者我有問題uiview動畫ipad風景模式。我有兩個視圖view1(如分割視圖)和view2(覆蓋剩餘的窗口)。當我觸摸移動從右到左view2它將覆蓋視圖1與移動animation.at同時,當我觸摸移動從左到右view2來適合舊的position.please分享您的想法UIview動畫覆蓋一個視圖到另一個視圖
隨着問候, Rajesh。
我是新的iphone開發者我有問題uiview動畫ipad風景模式。我有兩個視圖view1(如分割視圖)和view2(覆蓋剩餘的窗口)。當我觸摸移動從右到左view2它將覆蓋視圖1與移動animation.at同時,當我觸摸移動從左到右view2來適合舊的position.please分享您的想法UIview動畫覆蓋一個視圖到另一個視圖
隨着問候, Rajesh。
如果我理解正確,您需要2個視圖之間的滑動動畫。如果是這樣的話: 製作一個ViewController來保存這兩個視圖。這個視圖控制器的.m文件中定義包含以下並且得到由你的按鈕被稱爲過渡方法/其他動作觸發:
CGFloat windowWidth = self.mainView.frame.size.width;
CGFloat windowHeight = self.mainView.frame.size.height;
CGRect offScreenLeft = CGRectMake(-1*windowWidth, 0.0, windowWidth, windowHeight);
CGRect onScreen = self.mainView.frame;
CGRect offScreenRight = CGRectMake(windowWidth, 0.0, windowWidth, windowHeight);
if (direction == rightToLeft)
{
rightView.frame = offScreenRight;
[self.view addSubview:rightView];
[UIView animateWithDuration:0.65
animations:^{
leftView.frame = offScreenLeft;
rightView.frame = onScreen;
}
completion:^(BOOL finished){
[leftView removeFromSuperview];
}];
}else if (direction == leftToRight){
self.leftViewController.view.frame = offScreenLeft;
[UIView animateWithDuration:0.65
animations:^{
rightView.frame = offScreenRight;
leftView.frame = onScreen;
}
completion:^(BOOL finished){
[rightView removeFromSuperview];
}];
}
}
在一般情況下,要確保你所添加的子視圖的觀點目前在屏幕上,並確保你設置了合適的邊界。檢查你的觀點是不爲零:
if(myView){
// not nil. thats good
}else {
// nil. this is bad. make sure myView is being initialized properly (if at all)
}
最後,確保無論是不透明,也不在你的子視圖的alpha屬性設置爲0(你會在1,如果你想讓它完全顯示出來想這些和對於透明效果,在0和1之間)。
大家好我終於找到了答案,
- (void)viewDidLoad
{
UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightSwipeHandle:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
[recognizer setNumberOfTouchesRequired:1];
[secondView addGestureRecognizer:recognizer];
[recognizer release];
UISwipeGestureRecognizer *recognizerleft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftSwipeHandle:)];
[recognizerleft setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[recognizerleft setNumberOfTouchesRequired:1];
[secondView addGestureRecognizer:recognizerleft];
[recognizerleft release];
[self.view addSubview:secondView];
[super viewDidLoad];
}
//To set the frame position of the view
- (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer
{
NSLog(@"rightSwipeHandle");
[UIView beginAnimations:@"viewanimations" context:nil];
[UIView setAnimationDuration:0.8];
[UIView setAnimationDelegate:self];
secondView.frame=CGRectMake(360, 0, 660, 768);
[UIView commitAnimations];
}
//To set the frame position of the view
- (void)leftSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer
{
NSLog(@"leftSwipeHandle");
[UIView beginAnimations:@"viewanimations" context:nil];
[UIView setAnimationDuration:0.8];
[UIView setAnimationDelegate:self];
secondView.frame=CGRectMake(200, 0, 858, 768);
[UIView commitAnimations];
}