xcode7.1,iOS编程第四版里面的hypnosis程序触摸没有响应。
iOS模拟器和手机中都运行都不输出信息。
实现代码:
@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
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。