coding with objc & swift

禁用MPMoviePlayerController自带的缩放手势

| Comments

MPMoviePlayerController自带了一个UIPinchGestureRecognizer手势,用于把播放器切换到全屏模式。 但是当你想禁用掉这个自带的缩放手势的时候,你会发现很难办。因为你根本无法在MPMoviePlayerController.view.gestureRecognizers属性中找到这个缩放手势。那么,有什么办法可以把它禁用掉呢?Stackoverflow给出了答案:

1
2
3
4
5
6
7
8
9
10
11
//你可以在MPMoviePlayViewController的touchesBegan方法中把它禁用掉:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    for (UITouch *touch in touches) {
        NSArray *array = touch.gestureRecognizers;
        for (UIGestureRecognizer *gesture in array) {
            if (gesture.enabled && [gesture isMemberOfClass:[UIPinchGestureRecognizer class]]) {
                gesture.enabled = NO;
            }
        }
    }
}

Comments