[英]Button on iOS is not sending events on touchUpInside
我從自定義視圖中創建了一個.xib文件。 我為該視圖創建了.h / .m文件。 我將ctrl從按鈕拖動到頭文件以創建IBAction並將值設置為touchUpInside。 以下是發生的事情:
http://screencast.com/t/R1WTpK7xp
WTF?
它在按鈕外面時觸發事件?
編輯:
這是截圖:
投票結果是什么? 我沒有看到這一點。
View.h
#import <UIKit/UIKit.h>
#import "DrawingViewDelegate.h"
@interface DrawingBottomToolbarView : UIView
@property (weak) id <DrawingViewDelegate> delegate;
- (IBAction)lineSegmentButtonPush:(id)sender;
@end
View.m
#import "DrawingBottomToolbarView.h"
@implementation DrawingBottomToolbarView
@synthesize delegate;
- (id)initWithFrame:(CGRect)frame
{
NSLog(@"frame");
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self addSubview:[[[NSBundle mainBundle] loadNibNamed:@"DrawingBottomToolbarView" owner:self options:nil] objectAtIndex:0]];
//[[[NSBundle mainBundle] loadNibNamed:@"DrawingBottomToolbarView" owner:self options:nil] objectAtIndex:0];
//[self addSubview:self.];
}
return self;
}
//-(id)initWithCoder:(NSCoder *)aDecoder{
//
// NSLog(@"coder");
// if ((self = [super initWithCoder:aDecoder])){
// [self addSubview:[[[NSBundle mainBundle] loadNibNamed:@"DrawingBottomToolbarView" owner:self options:nil] objectAtIndex:0]];
// }
// return self;
//}
- (IBAction)lineSegmentButtonPush:(id)sender
{
NSLog(@"line push");
}
@end
我不知道問題出在哪里。
編輯2:
我嘗試將按鈕設置為插座並在代碼中添加目標/操作,同樣的事情發生:
。H
@property (weak, nonatomic) IBOutlet UIButton *lineSegmentButton;
.M
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self addSubview:[[[NSBundle mainBundle] loadNibNamed:@"DrawingBottomToolbarView" owner:self options:nil] objectAtIndex:0]];
self.currentSelectedPathSegment = NoneSegment;
[self.lineSegmentButton addTarget:self action:@selector(lineSegmentButtonPush:) forControlEvents:UIControlEventTouchUpInside];
}
return self;
}
編輯3:這是我添加兩個視圖的地方。 圖紙視圖是在代碼中創建的,bottomToolbar是從.xib文件創建的。
kBottomToolbarHeight是常量,其值與.xib文件中定義的高度相同。
- (void)viewWillAppear:(BOOL)animated
{
[self.view addSubview:self.drawingView];
[self.view addSubview:self.bottomToolbar];
CGRect selfRect = self.view.bounds;
CGRect drawingViewRect = selfRect;
CGRect bottomToobarRect = selfRect;
drawingViewRect.size.height = selfRect.size.height - kBottomToolbarHeight;
bottomToobarRect.size.height = kBottomToolbarHeight;
bottomToobarRect.origin.y = drawingViewRect.size.height;
self.drawingView.frame = drawingViewRect;
self.bottomToolbar.frame = bottomToobarRect;
}
您在截屏視頻中提及並顯示的行為與我在視圖層次結構中的某個位置具有UITapGestureRecognizer
的父視圖時所UITapGestureRecognizer
。
我不確定是否將您的問題標記為可能與我解決問題的副本。
作為參考,這不是iOS 6.0中的問題,只是早期版本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.