UIButton *imageBtn = [UIButton ...
imageBtn.adjustsImageWhenHighlighted = NO;
[imageBtn addTarget:self action:@selector(doSomething:) forControlEvents:UIControlEventTouchUpInside];
[imageBtn addTarget:self action:@selector(doHighlighted:) forControlEvents:UIControlEventTouchDown];
[imageBtn addTarget:self action:@selector(doHighlighted:) forControlEvents:UIControlEventTouchDragEnter];
[imageBtn addTarget:self action:@selector(doCancelHighlighted:) forControlEvents:UIControlEventTouchDragExit];
-(void)doSomething:(UIButton *)button{
...
[self performSelector:@selector(doCancelHighlighted:) withObject:button afterDelay:0.2f];
}
-(void)doHighlighted:(UIButton *)button{
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 300, 300)];
imageView.backgroundColor = [UIColor blackColor];
imageView.alpha = 0.7;
imageView.tag = 1000;
[button addSubview:imageView];
}
-(void)doCancelHighlighted:(UIButton *)button{
UIView *view = [button subviewWithTag:1000];
[UIView animateWithDuration:0.2f animations:^{
view.alpha = 0;
} completion:^(BOOL finished) {
[view removeFromSuperview];
}];
}
我有同樣的問題。開始認爲有沒有辦法解決這個問題... – jasongregori 2011-07-28 01:17:32