滑动手势不会因为崩溃/错误而无法正常工作

时间:2015-06-04 23:25:14

标签: ios swipe-gesture

我正在制作此新闻Feed页面,以便他们可以在页面上查看照片。当他们向左滑动时,用户可以看到下一张图像。该应用程序没有崩溃,但它没有工作。 这是我的.m文件

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSString *userName = [[NSUserDefaults standardUserDefaults]
                            stringForKey:@"PUN"];
    NSString *welcomeTheUser = [NSString stringWithFormat:@"Hello, %@", userName];
    [self.textToSayHelloUser setText:welcomeTheUser];



    //Swipe left
    UISwipeGestureRecognizer *swipeLeftView1234 = [[UISwipeGestureRecognizer alloc] initWithTarget:self                                       action:@selector(slideToLeftWithGestureRecognizer:)];
    swipeLeftView1234.direction = UISwipeGestureRecognizerDirectionLeft;
    //Swipe right
    UISwipeGestureRecognizer *swipeRightView2345 = [[UISwipeGestureRecognizer alloc] initWithTarget:self                                       action:@selector(slideToRightWithGestureRecognizer:)];
    swipeRightView2345.direction = UISwipeGestureRecognizerDirectionRight;

    //Configure Left Swipe
    [self.View1 addGestureRecognizer:swipeLeftView1234];
    [self.View2 addGestureRecognizer:swipeLeftView1234];
    [self.View3 addGestureRecognizer:swipeLeftView1234];
    [self.View4 addGestureRecognizer:swipeLeftView1234];

    //Configure Right Swipe
    [self.View2 addGestureRecognizer:swipeRightView2345];
    [self.View3 addGestureRecognizer:swipeRightView2345];
    [self.View4 addGestureRecognizer:swipeRightView2345];
    [self.View5 addGestureRecognizer:swipeRightView2345];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)slideToRightWithGestureRecognizer:(UISwipeGestureRecognizer *)gestureRecognizer{
    [UIView animateWithDuration:0.5 animations:^{
        self.View1.frame = CGRectOffset(self.View1.frame, 375.0, 0.0);
        self.View2.frame = CGRectOffset(self.View2.frame, 375.0, 0.0);
        self.View3.frame = CGRectOffset(self.View3.frame, 375.0, 0.0);
        self.View4.frame = CGRectOffset(self.View4.frame, 375.0, 0.0);
        self.View5.frame = CGRectOffset(self.View5.frame, 375.0, 0.0);

    }];
}

-(void)slideToLeftWithGestureRecognizer:(UISwipeGestureRecognizer *)gestureRecognizer{
    [UIView animateWithDuration:0.5 animations:^{
        self.View1.frame = CGRectOffset(self.View1.frame, -375.0, 0.0);
        self.View2.frame = CGRectOffset(self.View2.frame, -375.0, 0.0);
        self.View3.frame = CGRectOffset(self.View3.frame, -375.0, 0.0);
        self.View4.frame = CGRectOffset(self.View4.frame, -375.0, 0.0);
        self.View5.frame = CGRectOffset(self.View5.frame, -375.0, 0.0);
    }];
}

@end

有人可以告诉我为什么滑动手势不起作用。

编辑: 我的.m文件viewdidload

UISwipeGestureRecognizer *swipeLeftView1 = [[UISwipeGestureRecognizer alloc] initWithTarget:self                                       action:@selector(slideToLeftWithGestureRecognizer:)];
swipeLeftView1.direction = UISwipeGestureRecognizerDirectionLeft;
[self.View1 addGestureRecognizer:swipeLeftView1];
//Swipe left
UISwipeGestureRecognizer *swipeLeftView2 = [[UISwipeGestureRecognizer alloc] initWithTarget:self                                       action:@selector(slideToLeftWithGestureRecognizer:)];
swipeLeftView2.direction = UISwipeGestureRecognizerDirectionLeft;
 [self.View2 addGestureRecognizer:swipeLeftView2];
//Swipe right
UISwipeGestureRecognizer *swipeRightView2 = [[UISwipeGestureRecognizer alloc] initWithTarget:self                                       action:@selector(slideToRightWithGestureRecognizer:)];
swipeLeftView2.direction = UISwipeGestureRecognizerDirectionRight;
[self.View2 addGestureRecognizer:swipeRightView2];

UISwipeGestureRecognizer *swipeLeftView3 = [[UISwipeGestureRecognizer alloc] initWithTarget:self                                       action:@selector(slideToLeftWithGestureRecognizer:)];
swipeLeftView3.direction = UISwipeGestureRecognizerDirectionLeft;
[self.View3 addGestureRecognizer:swipeLeftView3];

UISwipeGestureRecognizer *swipeRightView3 = [[UISwipeGestureRecognizer alloc] initWithTarget:self                                       action:@selector(slideToRightWithGestureRecognizer:)];
swipeLeftView3.direction = UISwipeGestureRecognizerDirectionRight;
[self.View3 addGestureRecognizer:swipeRightView3];

UISwipeGestureRecognizer *swipeLeftView4 = [[UISwipeGestureRecognizer alloc] initWithTarget:self                                       action:@selector(slideToLeftWithGestureRecognizer:)];
swipeLeftView4.direction = UISwipeGestureRecognizerDirectionLeft;
[self.View4 addGestureRecognizer:swipeLeftView4];

UISwipeGestureRecognizer *swipeRightView4 = [[UISwipeGestureRecognizer alloc] initWithTarget:self                                       action:@selector(slideToRightWithGestureRecognizer:)];
swipeLeftView4.direction = UISwipeGestureRecognizerDirectionRight;
[self.View4 addGestureRecognizer:swipeRightView4];

UISwipeGestureRecognizer *swipeRightView5 = [[UISwipeGestureRecognizer alloc] initWithTarget:self                                       action:@selector(slideToRightWithGestureRecognizer:)];
swipeRightView5.direction = UISwipeGestureRecognizerDirectionRight;
[self.View5 addGestureRecognizer:swipeRightView5];

0 个答案:

没有答案