gpt4 book ai didi

ios - UIGestureRecognizer 崩溃

转载 作者:行者123 更新时间:2023-11-28 18:23:14 24 4
gpt4 key购买 nike

我添加了向上滑动手势到图像,但是当滑动时,应用程序崩溃并出现 BAD_EXEC 错误。

这是我的:

.h文件:

@interface MyViewController : UIViewController <UIGestureRecognizerDelegate>
{

UISwipeGestureRecognizer* swipeUpGesture;
IBOutlet UIImageView* myImage; //Connected from Interface Builder
IBOutlet UIScrollView* myScrollView;
}

@property (retain, nonatomic) UISwipeGestureRecognizer* swipeUpGesture;
@property (retain, nonatomic) IBOutlet UIImageView* myImage;
@property (retain, nonatomic) IBOutlet UIScrollView* myScrollView;

.m文件:

- (void)viewDidLoad
{

//myImage is inside of myScrollView

swipeUpGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swiped)];
[swipeUpGesture setDirection:UISwipeGestureRecognizerDirectionUp];
[swipeUpGesture setDelegate:self];
[myImage addGestureRecognizer: swipeUpGesture];

}


- (void)swiped:(UISwipeGestureRecognizer*)sentGesture
{
NSLog (@"swiped");
}

基本上,在 myView 中,我有 myScrollView。在 myScrollView 中,我有 myImage

当我运行上面的代码时,应用程序会一直运行,直到我向上滑动,然后它才真正识别出滑动,但没有到达 NSLog,崩溃并且我得到了 BAD_EXEC

提前致谢。

最佳答案

如果您使用addSubview,请执行以下操作:

[self addChildViewController:myViewController];

之后:

[self.view addSubView: myViewController.view];

然后在 View Controller 中使用 UISwipeGestureRecognizer。

关于ios - UIGestureRecognizer 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16525260/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com