하위 뷰로 일부 단추가있는 사용자 지정 UIView가 있습니다. 나는 touchesBegan/Moved/Ended를 사용하여 사용자의 손가락으로보기를 회전시킵니다. 문제는 단추에서 뷰를 끌거나 회전하려고 시도 할 때 touches
메서드가 호출되지 않는다는 것입니다. UIControlEventTouchUpInside
이벤트에 응답하는 버튼이 필요하지만보기로 드래그 한 경우 내보기가 회전합니다. this 질문과 this 질문을 보았지만 나에게 적합한 해결책을 찾지 못했습니다.UIButton 사용자 정의 UIView 내부에 필요합니다.
- (id)initWithFrame:(CGRect)frame andRadius:(float)Radius andViews:
(NSMutableArray *)AllViews
{
self = [super initWithFrame:frame];
if (self) {
radius = Radius;
allViews = AllViews;
for(int i = 0; i < [allViews count]; i++){
//the "currentView" is a UIButton
UIView *currentView = (UIView *)[allViews objectAtIndex:i];
[currentView setFrame:CGRectMake(frame.size.width/2 - 25 + radius * cos((2 * M_PI/[allViews count]) * i), frame.size.height/2 - 25 + radius * sin((2 * M_PI/[allViews count]) * i), 50, 50)];
[self addSubview:currentView];
}
[self setBackgroundColor:[UIColor redColor]];
[self setAlpha:.5];
}
return self;
}
//- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
//{
// for (UIView * view in [self subviews]) {
// if ([view pointInside:[self convertPoint:point toView:view] withEvent:event]) {
// return YES;
// }
// }
// return NO;
//}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self];
x = point.x;
y = point.y;
NSLog(@"touchesBegan");
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self];
float X = point.x;
float Y = point.y;
float a = sqrt(X * X + Y * Y);
float b = sqrt(x * x + y * y);
float c = sqrt((x - X) * (x - X) + (y - Y) * (y - Y));
float alpha = acos((a * a + b * b - (c * c))/(2 * a * b));
if(alpha == NAN)
alpha = 0;
alpha = -alpha;
[UIView beginAnimations:@"rotate" context:nil];
[UIView setAnimationDuration:0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
self.transform = CGAffineTransformRotate(self.transform, alpha);
[UIView commitAnimations];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView:self];
float X = point.x;
float Y = point.y;
float a = sqrt(X * X + Y * Y);
float b = sqrt(x * x + y * y);
float c = sqrt((x - X) * (x - X) + (y - Y) * (y - Y));
float alpha = acos((a * a + b * b - (c * c))/(2 * a * b));
alpha = -alpha;
[UIView beginAnimations:@"rotate" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
self.transform = CGAffineTransformRotate(self.transform, alpha);
[UIView commitAnimations];
NSLog(@"touchesEnded");
}
- (void)dealloc
{
[allViews release];
[super dealloc];
}
어떤 제안 : 여기
내 사용자 지정보기 코드?