touchesBegan:withEvent没有触发
JP_G 2017-03-03 12:34:58 看书自学,写了个触摸事件方法,但是不知道为什么没有触发
贴代码:
HyponsisView.m
#import "HyponsisView.h"
@interface HyponsisView()
@property (strong,nonatomic)UIColor *circleColor;
@end
@implementation HyponsisView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor clearColor];
self.circleColor = [UIColor lightGrayColor];
}
return self;
}
-(void)drawRect:(CGRect)rect{
CGRect bounds = self.bounds;
//根据bounds计算中心点
CGPoint center;
center.x = bounds.origin.x+bounds.size.width/2.0;
center.y = bounds.origin.y+bounds.size.height/2.0;
//矩形外接圆的半径
float maxRadius = hypotf(bounds.size.width, bounds.size.height)/2.0;
UIBezierPath *path = [[UIBezierPath alloc] init];
for(float radius = maxRadius;radius > 0;radius -= 20){
[path moveToPoint:CGPointMake(center.x+radius, center.y)];
//NSLog(@"%f %f %f",center.x,center.y,radius);
[path addArcWithCenter:center
radius:radius startAngle:0.0
endAngle:M_PI*2.0
clockwise:YES];
}
//设置线条宽度为10
path.lineWidth = 10;
//设置绘制颜色为浅灰色
//[[UIColor lightGrayColor] setStroke];
[self.circleColor setStroke];
//绘制路径
[path stroke];
//添加图像
//UIImage *logoImage = [UIImage imageNamed:@"logo.png"];
//[logoImage drawInRect:rect];
}
-(void)setCircleColor:(UIColor *)circleColor{
_circleColor = circleColor;
[self setNeedsDisplay];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"Touch");
}
@end