开发者

UIButton - changing frame alters response to touches

I have a UIButton. I found that when I moved it, it no longer responded to touches. Let me explain in detail how I determined this: when I shift a 100pixel width button by 50 pixe开发者_运维技巧ls to the right, only the left half responded to my finger tapping it.

How do I tell the button "update your touches checker" when I dynamically change the frame of it? I am changing the frame in code, NOT in xib.

Initialization:

    MATCGlossyButton *repeat = [[MATCGlossyButton alloc] init];
    [repeat addTarget:self action:@selector(repeatPressed:) forControlEvents:UIControlEventTouchUpInside];
    [repeat setTitle:@"Repeat" forState:UIControlStateNormal];
    repeat.buttonColor = [UIColor brownColor];
    repeat.backgroundColor = [UIColor clearColor];
    repeat.cornerRadius = 20;
    repeat.frame = CGRectMake(200,208,105,50);

And then later on:

repeat.frame = CGRectMake(265, 208, 105, 50);


Is it possible you are moving the button beyond the bounds of its parent view? Even if clipping is off, touches aren't propagated outside of a view.

An easy way to visualise the borders of your views is to do the folowing:

#import <QuartzCore/QuartzCore.h>

[...]

view.layer.borderWidth = 1;
view.layer.borderColor = [UIColor redColor].CGColor;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜