Having a little trouble with my app. I am questioning my approach.
Here is an image 
Basically i need the color wheel to spin in the transparent box. What I have so far is working. I can drag the color wheel and it will rotate. The problem is I can touch and drag ‘anywhere’ on the screen and it will rotate. I only want it to rotate in the ‘window’.
I basically added a UIView and an UIImageView, added outlets to the ImageView and added code in touchesBegan and touchesMoved to perform the animation. The wheel is a full circle image and subviews are ‘clipped’ to no show the lower half of the image.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *thisTouch = [touches anyObject];
delta = [thisTouch locationInView:wheelImage];
float dx = delta.x - wheelImage.center.x;
float dy = delta.y - wheelImage.center.y;
deltaAngle = atan2(dy,dx);
initialTransform = wheelImage.transform;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint pt = [touch locationInView:wheelImage];
float dx = pt.x - wheelImage.center.x;
float dy = pt.y - wheelImage.center.y;
float ang = atan2(dy,dx);
//do the rotation
if (deltaAngle == 0.0) {
deltaAngle = ang;
initialTransform = wheelImage.transform;
}else
{
float angleDif = deltaAngle - ang;
CGAffineTransform newTrans = CGAffineTransformRotate(initialTransform, -angleDif);
wheelImage.transform = newTrans;
currentValue = [self goodDegrees:radiansToDegrees(angleDif)];
}
}
Now…My questions are the following:
- How can I get the touchesMoved/Began ONLY to work on the UIView or UIImageView?
- Should I create a Custom UIView for this wheel and then just add it to my main view controller?
2.a. If I do create a custom, will I have the same issue with the touches?
You may want to consider using a UISwipeGestureRecognizer and adding it to only the view in which you wish to recognize the swipe.