首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >iOS编程4第112页中的版本touchesBegan:(NSSet *)触摸无法响应

iOS编程4第112页中的版本touchesBegan:(NSSet *)触摸无法响应
EN

Stack Overflow用户
提问于 2016-07-02 18:46:09
回答 1查看 28关注 0票数 0

1)未响应-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent*)event方法。

2)关于绘制同心圆app

3) Xcode 7.3.1

代码语言:javascript
运行
复制
#import "BNRHypnosisView.h"
@interface BNRHypnosisView ()

@property(nonatomic,strong)UIColor *circleColor;
@end
@implementation BNRHypnosisView

-(void)drawRect:(CGRect)rect {
    CGRect bounds = self.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 currentRadius = maxRadius; currentRadius > 0 ; currentRadius -=20) {
        [path moveToPoint:CGPointMake(center.x + currentRadius, center.y)];
        [path addArcWithCenter:center radius:currentRadius startAngle:0.0 endAngle:M_PI * 2.0 clockwise:YES];
    }
    path.lineWidth= 5;
    [self.circleColor setStroke];
    [path stroke];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.circleColor = [UIColor blackColor];
        self.backgroundColor = [UIColor whiteColor];

            }
    return self;
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{

    NSLog(@"%@ was touched.",self);
    float red = (arc4random() % 100) /100.0;
    float green = (arc4random() % 100) /100.0;
    float blue = (arc4random() % 100) /100.0;
    UIColor *radomColor = [UIColor colorWithRed:red green:green blue:blue alpha:1.0];
    self.circleColor = radomColor;
}
-(void)setCricleColor:(UIColor *)circleColor
{
    _circleColor = circleColor;
    [self setNeedsDisplay];
}
@end
EN

回答 1

Stack Overflow用户

发布于 2016-07-05 21:31:52

确保视图的UserInteractionEnabled为true。

代码语言:javascript
运行
复制
[self.NameOfBNRHypnosisView setUserInteractionEnabled:true];

Also, I found one mistake in your method code. Use setCircleColor instead of setCricleColor.

-(void)setCircleColor:(UIColor *)circleColor
{
    _circleColor = circleColor;
    [self setNeedsDisplay];
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38159247

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档