开发者社区> 问答> 正文

touchesBegin:withEvent:方法不响应。

xcode7.1,iOS编程第四版里面的hypnosis程序触摸没有响应。

iOS模拟器和手机中都运行都不输出信息。

实现代码:

import "BNRHypnosisView.h"//头文件为空。

@interface BNRHypnosisView ()

@property (nonatomic,strong) UIColor *circleColor;

@end

@implementation BNRHypnosisView

-(void)touchesBegan:(NSSet )touches withEvent:(UIEvent )event//触摸无响应。不输出信息。
{

 
 
float red=(arc4random()%100)/100.0;
float green=(arc4random()%100)/100.0;
float blue=(arc4random()%100)/100.0;
 
UIColor *randomColor=[UIColor colorWithRed:red green:green blue:blue alpha:1.0];
self.circleColor=randomColor;
NSLog(@"%@ was touched",self);
 

}

-(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;
 
//calculate the center of circle by 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=hypot(bounds.size.height, bounds.size.width);
 
UIBezierPath *path=[[UIBezierPath alloc]init];
 
 
for(float currentRadius=maxRadius;currentRadius>0;currentRadius-=20){
    //remove radius drawing in screen
    [path moveToPoint:CGPointMake(center.x+currentRadius, center.y)];//let the pen start at the new circle's curve,instead of center!
    [path addArcWithCenter:center radius:currentRadius startAngle:0 endAngle:M_PI*2 clockwise:YES];
}

path.lineWidth=5;
[self.circleColor setStroke];//color of line
 
[path stroke];//draw
 

}
-(void)setCircleColor:(UIColor *)circleColor
{

_circleColor=circleColor;
[self setNeedsDisplay];

}

@end

展开
收起
杨冬芳 2016-06-27 11:34:22 2106 0
0 条回答
写回答
取消 提交回答
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载