0
1)メソッド-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent*)event
に応答しません。
2)およそ7.3.1iOSプログラミング4thEdition in page:112 touchesBegan:(NSSet *)タッチが応答できません
#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
「 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)」イベントメソッドは、UIViewクラスへのタッチにのみ応答します。 – Bharat
どうすればいいですか? –
'UITapGestureRecognizer'を試してみてください。 – Bharat