0

スワイプするとビューを変更しようとしています。背景色を変更してこれをテストしたので、スワイプ作業が見つかりました。

それ以来、新しい view.nib を追加し、クラスを現在のビューと同じに設定しました。このclasses .hファイル内でこれを行いました

@interface MasterViewController : UIViewController <UIGestureRecognizerDelegate>{

    UIView *myView;
    UIView *secondView;
}

@property (strong, nonatomic) IBOutlet UIView *myView; // attached to Viewcontroller nib
@property (strong, nonatomic) IBOutlet UIView *secondView; // attached to the secondView


- (void)swipedScreen;

MyView は最初に表示されるメイン ビューです。secondView は、このビューに関連するようにクラスを作成および変更した nib のビューです。

そこから、.mファイルでこれを行いました

- (void) setupSwipeGestureRecognizer {
    UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipedScreen)];
    swipeGesture.direction = (UISwipeGestureRecognizerDirectionRight|UISwipeGestureRecognizerDirectionLeft);
    [myView addGestureRecognizer:swipeGesture];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"Prototype";
    [self setupSwipeGestureRecognizer];
}

- (void)swipedScreen
{
    // Not sure what to do here.
    [[NSBundle mainBundle] loadNibNamed:@"SecondView" owner:self options:nil];

}

secondView を表示するために swipedScreen メソッドで何をすべきかわかりません..このビューをアニメーション化して右からスライドインしたいと思います..ここで何が間違っているのかわかりませんが、明らかに非常に基本的なことです。

どんな助けでも大歓迎です。

4

1 に答える 1

0

私がコメントしたように:

- (void)swipedScreen
{
    [UIView animateWithDuration:3.0f delay:0 options:UIViewAnimationOptionCurveLinear
                 animations:^{ 
                         secondView.frame = CGRectMake(180, secondView.frame.origin.y, secondView.frame.size.width, secondView.frame.size.height);
                     }
                 completion:^(BOOL finished){
                         myView.hidden = YES;
                 }];
}

実際には、アニメーション化する必要に応じてX、Y、幅、高さの値を変更する必要があります。それが完了したら、メインビューを非表示に設定しmyViewます。

于 2012-05-29T01:45:00.897 に答える