當用戶觸摸我的UIButton
子類時,我希望該按鈕向外擴展大小。但是,當我在touchDown事件中操作按鈕的框架時,什麼都不會發生。 touchDown事件正在被調用,我可以改變其他屬性,如顏色,但不是框架。在iPhone中觸摸時展開UIButton
這是怎麼回事?
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self addTarget:self action:@selector(touchDown:) forControlEvents:UIControlEventTouchDown];
}
return self;
}
- (void)touchDown:(id)sender {
self.frame = CGRectInset(self.frame, -20, -20);
}
編輯:按鈕嵌套深視圖體系內的,但每個具有上海華clipsToBounds = NO
。
看一看CGRectInset(CGRect矩形,CGFloat dx,CGFloat dy),一點清潔劑。只需使用dx和dy的負數即可展開。 http://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CGGeometry/Reference/reference.html#//apple_ref/c/func/CGRectInset –