声明 UITouchGestures?

发布于 2024-11-03 03:38:51 字数 907 浏览 5 评论 0原文

我正在使用 UISwipeGestureRecognizerDirectionRight 方法来更改应用程序中的视图,并且我在视图控制器的主文件中使用了以下代码,但似乎我需要在星号之后定义手势并将其声明为此版本错误状态: “swipeGesture 未声明”

-(void)createGestureRecognizers {
UISwipeGestureRecognizerDirectionRight * swipeGesture = [[UISwipeGestureRecognizerDirectionRight alloc]
                                                        initWithTarget:self
                                                        action:@selector (handleSwipeGestureRight:)];
[self.theView addGestureRecognizer:swipeGesture];
[swipeGesture release];
}

-(IBAction)handleSwipeGestureRight {
NC2ViewController *second2 =[[NC2ViewController alloc] initWithNibName:@"NC2ViewController" bundle:nil];
second2.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:second2 animated:YES];
[second2 release];

}

所以我的问题是如何在头文件中的星号后面声明“swipeGesture”或者我做错了什么?

谢谢

I'm working on using a UISwipeGestureRecognizerDirectionRight method to change views within an application and i have used the following code in the main file of the View Controller but it seems as though i need to define the gesture after the asterisk and declare it as this build error states:
"swipeGesture undeclared"

-(void)createGestureRecognizers {
UISwipeGestureRecognizerDirectionRight * swipeGesture = [[UISwipeGestureRecognizerDirectionRight alloc]
                                                        initWithTarget:self
                                                        action:@selector (handleSwipeGestureRight:)];
[self.theView addGestureRecognizer:swipeGesture];
[swipeGesture release];
}

-(IBAction)handleSwipeGestureRight {
NC2ViewController *second2 =[[NC2ViewController alloc] initWithNibName:@"NC2ViewController" bundle:nil];
second2.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:second2 animated:YES];
[second2 release];

}

So my question is how do i declare the "swipeGesture" after the asterisk in the header file or have i done something wrong?

Thank You

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

把昨日还给我 2024-11-10 03:38:51

UISwipeGestureRecognizerDirectionRight 是四个可能方向的枚举值。它不是您实例化来识别手势的类。使用 UISwipeGestureRecognizer 代替:

UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] 
                               initWithTarget:self 
                               action:@selector (handleSwipeGestureRight:)];

//Set the direction you want to detect by setting 
//the recognizer's direction property...
//(the default is Right so don't really need it in this case)
swipeGesture.direction = UISwipeGestureRecognizerDirectionRight;

[self.view addGestureRecognizer:swipeGesture];
[swipeGesture release];

此外,处理程序方法应该是:

-(IBAction)handleSwipeGestureRight:(UISwipeGestureRecognizer *)swipeGesture {

因为在操作的选择器中,您在方法名称中放置了一个冒号,这意味着您希望它将发送者对象作为第一个参数传递。 (如果您不需要处理程序中的发送者,您也可以从选择器中删除冒号。)

最后,在处理程序中,voidIBAction 更合适,因为它不会从 xib 中的对象调用。但是,由于 IBAction 和 void 是同一件事,因此不会造成问题。

UISwipeGestureRecognizerDirectionRight is an enum value for the four possible directions. It is not a class you instantiate to recognize gestures. Use UISwipeGestureRecognizer instead:

UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] 
                               initWithTarget:self 
                               action:@selector (handleSwipeGestureRight:)];

//Set the direction you want to detect by setting 
//the recognizer's direction property...
//(the default is Right so don't really need it in this case)
swipeGesture.direction = UISwipeGestureRecognizerDirectionRight;

[self.view addGestureRecognizer:swipeGesture];
[swipeGesture release];

Also, the handler method should be:

-(IBAction)handleSwipeGestureRight:(UISwipeGestureRecognizer *)swipeGesture {

because in the selector for the action, you put a colon in the method name meaning you want it to pass the sender object as the first parameter. (You could also remove the colon from the selector instead if you don't need the sender in the handler.)

Finally, void is more appropriate than IBAction in the handler since it won't be called from an object in a xib. However, since IBAction and void are the same thing, it won't cause a problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文