【发布时间】:2013-02-25 23:11:04
【问题描述】:
这是我的代码:
@implementation myView2
{
BOOL _touchHasBegun;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
_touchHasBegun = YES;
}
- (void)drawRect:(CGRect)rect
{
if (_touchHasBegun == YES)
{
NSLog(@"fjnv");
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBStrokeColor(context, 0, 0, 225, 1);
CGContextSetRGBFillColor(context, 0, 0, 255, 1);
CGRect rectangle = CGRectMake(50, 50, 500, 500);
CGContextStrokeEllipseInRect(context, rectangle);
}
}
我还尝试在UIView 之上使用UIButton 并在按钮操作方法中设置CGRect。但这不起作用。这段代码也没有。怎么了?
【问题讨论】:
-
我认为您需要添加 [super touchesBegan:touches withEvent:event] 以正确保持触摸行为。
-
我应该将它添加到 if 语句中吗?
-
@Kirualex 我应该将它添加到 if 语句中吗?
-
不要像这样添加它: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesBegan:touches withEvent:event]; _touchHasBegun = 是; }
标签: objective-c ipad cocoa-touch quartz-graphics