3

カスタムビューから.xibファイルを作成しました。そのビュー用に.h/.mファイルを作成しました。ボタンからヘッダーファイルにCtrlキーを押しながらドラッグして、IBActionを作成し、値をtouchUpInsideに設定しました。これが起こっていることです:

http://screencast.com/t/R1WTpK7xp

WTF?

upがボタンの外側にあるときにイベントをトリガーしますか?

編集:

スクリーンショットは次のとおりです。

ここに画像の説明を入力してください

そして、反対票のあるものは何ですか?その意味はわかりません。

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:ここに2つのビューを追加します。図面ビューはコードで作成され、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;    
}
4

1 に答える 1

0

あなたが言及してスクリーンキャストに表示する動作は、ビュー階層のどこかに。が付いた親ビューがあったときに経験したものとまったく同じUITapGestureRecognizerです。

私の問題を解決するのに役立ったこの質問の重複の可能性としてあなたの質問にフラグを立てるかどうかはわかりません。

参考までに、これはiOS 6.0では問題ではなく、以前のバージョンでのみ問題になります。

于 2012-11-09T14:29:08.793 に答える