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

时间:2015-12-05 02:06:37

标签: objective-c tvos apple-tv

如何使用Objective C for tvOS识别远程滑动和按钮水龙头?我找到的任何地方都有Swift,我还不习惯。

谢谢!

2 个答案:

答案 0 :(得分:4)

示例中的Swift代码:

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

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

转换为目标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");
}

这似乎有效:

enter image description here

答案 1 :(得分:0)

例如快速代码。

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.

}