【发布时间】:2011-02-09 21:33:43
【问题描述】:
我在视图中有一个 UIBezierPath。我想在单击形状时显示警报,但实际发生的情况是,不仅在我单击形状时显示警报,而且当我单击视图中的任何位置时都会显示警报。
如何更改此代码,以便仅当我在彩色形状内单击时才会收到警报? 另外,如何使形状在屏幕上可拖动?
#import "draw2D.h"
@implementation draw2D
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code.
}
return self;
}
- (void)drawRect:(CGRect)rect {
UIBezierPath* aPath = [UIBezierPath bezierPath];
[aPath moveToPoint:CGPointMake(200.053,79.688)];
[aPath addLineToPoint:CGPointMake(100.053,179.688)];
[aPath addLineToPoint:CGPointMake(304.412,280.125)];
[aPath addLineToPoint:CGPointMake(308.055,298.513)];
[aPath addLineToPoint:CGPointMake(200.053,79.688)];
[aPath closePath];
[[UIColor blackColor] setStroke];
[[UIColor redColor] setFill];
CGContextRef aRef = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(aRef, 50, 50);
aPath.lineWidth = 5;
[aPath fill];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title" message:@"Some message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles: nil];
//After some time
[alert show];
[alert release];
}
- (void)dealloc {
[super dealloc];
}
@end
【问题讨论】:
标签: iphone cocoa-touch ios uikit core-graphics