ios - 添加 UITapGestureRecognizer 时 UIImageView 崩溃

标签 ios uiimageview gesture uicontrol uitapgesturerecognizer

@interface OOTRotaryWheel : UIControl


@property (weak) id <OOTRotaryProtocol> delegate;
@property (nonatomic, strong) UIView *container;
@property int numberOfSections;
@property CGAffineTransform startTransform;
@property (nonatomic, strong) NSMutableArray *sectors;
@property int currentSector;
@property (nonatomic, retain) UIImageView *mask;

- (id) initWithFrame:(CGRect)frame andDelegate:(id)del withSections:(int)sectionsNumber;
- (void)rotate;
- (void) buildSectorsEven;
- (void) buildSectorsOdd;

@end

在我的 .m 文件中

我的初始化方法

mask = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 58, 58)];
mask.image =[UIImage imageNamed:@"centerButton.png"];
mask.center = self.center;
mask.center = CGPointMake(mask.center.x, mask.center.y+3);
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(buttonPressedDown:)];
[mask addGestureRecognizer:singleTap];
[mask setMultipleTouchEnabled:YES];
[mask setUserInteractionEnabled:YES];



-(IBAction)buttonPressedDown
{
    //Connect this IBAction to touchDown
    mask.alpha = 0.5f;
    NSLog(@"tapping the center of the earth");
}

当我点击图片时,它崩溃并显示此消息

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[OOTRotaryWheel buttonPressedDown:]: unrecognized selector sent to instance 0x71724e0'
*** First throw call stack:

我以编程方式绘制了 UI,因此 Interface Builder 中没有 UI 元素。我的 UI 是一个 Storyboard,但它是空的。

最佳答案

您在执行 buttonPressedDown: 时忘记了冒号。要么去掉 singleTap 定义的 action 参数中的冒号,要么将冒号和参数添加到您的实现中。

关于ios - 添加 UITapGestureRecognizer 时 UIImageView 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12696186/

相关文章:

ios - objective-C - 如何在我的 TableView 中保留内存中的动态控制对象

ios - 在 UIView 中将一个 ImageView 和一个 UILabel 居中

iphone - 在 iPhone 5 和 iPhone 4 的 xib 中处理不同尺寸的图像?

qt - 自定义 QGestureRecognizer 和 QTouchEvents

ios - 在 Xcode beta 4 中设置 UITableViewCell 委托(delegate)时崩溃

ios - scheduleLocalNotification 在 Swift 2.0 中不起作用

ios - 取消与 iOS 中的按钮关联的展开操作

ios - 将 UIImageView 放置在另一个具有缩放功能的上方

android - Android listview打开手势的实现方法

iphone - longpress手势识别器不适用于 map View 上的用户位置(MKuserlocation)-iOS