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
...全文
289 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
JP_G 2017-03-05
  • 打赏
  • 举报
回复
再补充一点,将此方法在AppDelegate.m中重写时,可以触发。我另外查阅了一下,说是被某个响应者拦截了,不太看得懂是什么意思,希望大家指点一下。
JP_G 2017-03-05
  • 打赏
  • 举报
回复
补充一点,我这个类是继承UIView的
JP_G 2017-03-03
  • 打赏
  • 举报
回复
有木有大神帮看下

29,027

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧