繁体   English   中英

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

[英]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.

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