tvOS 如何识别 Objective C 的远程手势?

tvOS how to recognize remote gestures for Objective C?

我如何使用 Objective C 为 tvOS 识别远程滑动和按钮点击?我发现到处都是 Swift,我还不习惯。

谢谢!

您示例中的 Swift 代码:

let swipeDown:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("swipedDown:"))
swipeDown.direction = .Down
view.addGestureRecognizer(swipeDown)

func swipedDown(sender:UISwipeGestureRecognizer){
    NSLog("It worked")
}

Swift 5:

let swipeDown:UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("swipedDown:"))
swipeDown.direction = .down
view.addGestureRecognizer(swipeDown)

func swipedDown(sender:UISwipeGestureRecognizer){
    NSLog("It worked")
}

翻译成Objective C:

- (void)viewDidLoad {
    [super viewDidLoad];

    UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeDown:)];
    recognizer.direction = UISwipeGestureRecognizerDirectionDown;
    [self.view addGestureRecognizer:recognizer];
}

- (void)swipeDown:(UISwipeGestureRecognizer *)sender
{
    NSLog(@"It works");
}

这似乎有效:

例如 swift 代码。

let tapRecognizer = UITapGestureRecognizer(target: self, action: "tapped")
tapRecognizer.allowedPressTypes = [NSNumber(integer:  UIPressType.Select.rawValue)];
self.tabBar.addGestureRecognizer(tapRecognizer)

let swipeRecognizerRight = UISwipeGestureRecognizer(target: self, action: "swipedRight")
swipeRecognizerRight.direction = .Right //.Left,.Up,.Down.
self.tabBar.addGestureRecognizer(swipeRecognizer)

还有这些方法:

func tapped(){

    // write her your code.

}

func swipeRecognizer(){

   // write her your code.

}