SwipeGesture帮助?只有LeftSwipe可以使用但RightSwipe不能

时间:2012-10-28 17:28:39

标签: iphone ios ipad swipe gesture

会发生什么;当我向左滑动textView改变帧大小这是我想要它做的但是当我向右滑动textView不会改变回我想要的方式,实际上它根本没有改变!
有什么帮助吗?

// Add swipeGestures
    UISwipeGestureRecognizer *SwipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeReconised:)];
    [SwipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
    [self.view addGestureRecognizer:SwipeLeft];

    UISwipeGestureRecognizer *SwipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeReconised:)];
    [SwipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
    [self.view addGestureRecognizer:SwipeRight];
}
- (void)swipeReconised:(UISwipeGestureRecognizer *)Swipe {
if (Swipe.direction == UISwipeGestureRecognizerDirectionLeft) {
    CGRect frame = [TextView frame];
    frame.size.width = 750;//Some value
    frame.size.height = 655;//some value
    frame.origin.x = 275;
    frame.origin.y = 44;
    [TextView setFrame:frame];
if (Swipe.direction == UISwipeGestureRecognizerDirectionRight) {
    CGRect frame = [TextView frame];
    frame.size.width = 240;//Some value
    frame.size.height = 655;//some value
    frame.origin.x = 784;
    frame.origin.y = 44;
    [TextView setFrame:frame];
        }
    }
}

1 个答案:

答案 0 :(得分:1)

if (Swipe.direction == UISwipeGestureRecognizerDirectionLeft)的开场词应在if (Swipe.direction == UISwipeGestureRecognizerDirectionRight)之前关闭,然后才能调用

- (void)swipeReconised:(UISwipeGestureRecognizer *)Swipe {
if (Swipe.direction == UISwipeGestureRecognizerDirectionLeft) {
    CGRect frame = [TextView frame];
    frame.size.width = 750;//Some value
    frame.size.height = 655;//some value
    frame.origin.x = 275;
    frame.origin.y = 44;
    [TextView setFrame:frame];
}
if (Swipe.direction == UISwipeGestureRecognizerDirectionRight) {
    CGRect frame = [TextView frame];
    frame.size.width = 240;//Some value
    frame.size.height = 655;//some value
    frame.origin.x = 784;
    frame.origin.y = 44;
    [TextView setFrame:frame];
    }
}