2012-07-19 216 views
2

我是新的iphone开发者我有问题uiview动画ipad风景模式。我有两个视图view1(如分割视图)和view2(覆盖剩余的窗口)。当我触摸移动从右到左view2它将覆盖视图1与移动animation.at同时,当我触摸移动从左到右view2来适合旧的position.please分享您的想法UIview动画覆盖一个视图到另一个视图

随着问候, Rajesh。

回答

1

如果我理解正确,您需要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之间)。

3

大家好我终于找到了答案,

- (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]; 

} 
相关问题