iphone - 滑动手势有帮助吗?仅 LeftSwipe 有效,而 RightSwipe 无效

标签 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];
        }
    }
}

最佳答案

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

关于iphone - 滑动手势有帮助吗?仅 LeftSwipe 有效,而 RightSwipe 无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13111218/

相关文章:

iphone - 一起使用 AVCaptureSession 和 AVAudioPlayer

iphone - iOS 本地化 : Create strings-file for native language?

iphone - 当发布的App对User Interaction无响应时,有什么好的方法可以获取有用的信息?

iphone - 如何在 iPhone 应用程序中列出单个开发人员的所有 iPhone 应用程序?

objective-c - 接收远程推送通知时打开 View Controller

iOS:如何从 CGContextRef 检索图像尺寸 X、Y

objective-c - 如何从 View Controller 中 resignFirstResponder

iphone - 将 UIAlertView 添加到 UIScrollView

ios - UITableViewCell 之间的间距有多高?

objective-c - App 在 iPad 1 上崩溃,但在 iPad 2 或第 3 代上不会