简体   繁体   English

iOS上的按钮不会在touchUpInside上发送事件

[英]Button on iOS is not sending events on touchUpInside

I created a .xib file form my custom view. 我从自定义视图中创建了一个.xib文件。 I created .h/.m files for that view. 我为该视图创建了.h / .m文件。 I ctrl dragged from button to header file to create an IBAction and set the value to touchUpInside. 我将ctrl从按钮拖动到头文件以创建IBAction并将值设置为touchUpInside。 Here is what is happening: 以下是发生的事情:

http://screencast.com/t/R1WTpK7xp http://screencast.com/t/R1WTpK7xp

WTF? WTF?

It triggers event when up is outside the button? 它在按钮外面时触发事件?

EDIT: 编辑:

Here is the screenshot: 这是截图:

在此输入图像描述

And what is the thing with down vote? 投票结果是什么? I don't see a point in that. 我没有看到这一点。

View.h View.h

#import <UIKit/UIKit.h>
#import "DrawingViewDelegate.h"

@interface DrawingBottomToolbarView : UIView

@property (weak) id <DrawingViewDelegate> delegate;

- (IBAction)lineSegmentButtonPush:(id)sender;

@end

View.m 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

I don't get it where is the problem. 我不知道问题出在哪里。

EDIT 2: 编辑2:

I tried setting buttons as outlets and add target/action in code and same thing happens: 我尝试将按钮设置为插座并在代码中添加目标/操作,同样的事情发生:

.h 。H

@property (weak, nonatomic) IBOutlet UIButton *lineSegmentButton;

.m .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;
}

EDIT 3: Here is where I add two views. 编辑3:这是我添加两个视图的地方。 drawing view is created in code, bottomToolbar is created from .xib file. 图纸视图是在代码中创建的,bottomToolbar是从.xib文件创建的。

kBottomToolbarHeight is constant with same value as height defined in .xib file. 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;    
}

The behavior you mention and show in the screencast is exactly the same as I experienced when I somewhere in the view hierarchy had a parent view with a UITapGestureRecognizer . 您在截屏视频中提及并显示的行为与我在视图层次结构中的某个位置具有UITapGestureRecognizer的父视图时所UITapGestureRecognizer

I'm unsure whether or not to flag your question as a possible duplicate of this one which helped me solve my problem . 我不确定是否将您的问题标记为可能与我解决问题的副本。

For reference this is not a problem in iOS 6.0, only earlier versions. 作为参考,这不是iOS 6.0中的问题,只是早期版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM