2

私は新しいiphone開発者ですipadランドスケープモードのuiviewアニメーションに問題があります.2つのビューview1(分割ビューのような)とview2(覆われた残りのウィンドウ)があります。右から左に移動view2をタッチすると、view1がオーバーライドされますアニメーションの移動。タッチすると同時に左から右への移動view2が来て、古い位置に合わせます。アイデアを共有してください

よろしく、ラジェッシュ。

4

2 に答える 2

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

}
于 2012-07-20T07:31:45.360 に答える
1

私の理解が正しければ、2 つのビュー間でスライドするアニメーションが必要です。その場合: これら 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]; 
                     }]; 
    } 
}

一般に、現在画面に表示されているビューにサブビューを追加していることを確認し、適切な境界を設定していることを確認してください。ビューが nil でないことを確認します。

if(myView){
    //  not nil. thats good
}else {
    //  nil. this is bad. make sure myView is being initialized properly (if at all)
}

最後に、サブビューの opacity プロパティも alpha プロパティも 0 に設定されていないことを確認します (完全に表示する場合は 1 に設定し、透明効果を得るには 0 と 1 の間に設定します)。

于 2012-07-19T21:35:15.943 に答える