Ich möchte das Bild im oder gegen den Uhrzeigersinn drehen entsprechend dem Benutzer berühren ziehen mit seiner Geschwindigkeit. Ich denke, das kann mit etwas Mathe und Logik getan werden. Wie sieht ein Codebeispiel dafür aus?Drehen Sie das Bild entsprechend der Touch ziehen in iPhone
9
A
Antwort
16
Wenn Sie iOS 3.2 oder höher verwenden, können Sie UIRotationGestureRecognizer
verwenden. Der Code würde wie folgt aussehen:
In Ihrem Setup-Methode (viewDidLoad
oder init
usw.):
UIRotationGestureRecognizer *rotationGesture =
[[UIRotationGestureRecognizer alloc] initWithTarget:self
action:@selector(handleRotate:)];
rotationGesture.delegate = self;
[myImageView addGestureRecognizer:rotationGesture];
[rotationGesture release];
Der Event-Handler:
- (void)handleRotate:(UIRotationGestureRecognizer *)recognizer {
if(recognizer.state == UIGestureRecognizerStateBegan ||
recognizer.state == UIGestureRecognizerStateChanged)
{
recognizer.view.transform = CGAffineTransformRotate(recognizer.view.transform,
recognizer.rotation);
[recognizer setRotation:0];
}
}
Ich habe einige weitere Beispiele für Geste Erkenner (einschließlich der oben genannten) auf github.
2
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UITouch *touch in touches)
{
currentTouch=touch;
if (CGRectContainsPoint([self.view frame], [touch locationInView:self.ViewRotationArrow]))
{
[self transformSpinnerwithTouches:touch];
}
else if (!CGRectContainsPoint([ViewRotationArrow frame], [touch locationInView:self.ViewRotationArrow])) {
[self dispatchTouchEvent:[touch view]WithTouch:touch];
}
}
}
-(void)transformSpinnerwithTouches:(UITouch *)touchLocation
{
CGPoint touchLocationpoint = [touchLocation locationInView:self.view];
CGPoint PrevioustouchLocationpoint = [touchLocation previousLocationInView:self.view];
//Origin is the respective point. From that I am going to measure the
//angle of the current position with respect to the previous position ....
CGPoint origin;
origin.x=240;
origin.y=160;
//NSLog(@"currentTouch Touch In Location In View:%F %F\n",touchLocationpoint.x,touchLocationpoint.y);
//NSLog(@"currentTouch Touch previous Location In View:%F %F\n",PrevioustouchLocationpoint.x,PrevioustouchLocationpoint.y);
CGPoint previousDifference = [self vectorFromPoint:origin toPoint:PrevioustouchLocationpoint];
CGAffineTransform newTransform =CGAffineTransformScale(ViewRotationArrow.transform, 1, 1);
CGFloat previousRotation = atan2(previousDifference.y, previousDifference.x);
CGPoint currentDifference = [self vectorFromPoint:origin toPoint:touchLocationpoint];
CGFloat currentRotation = atan2(currentDifference.y, currentDifference.x);
CGFloat newAngle = currentRotation- previousRotation;
NSLog(@"currentRotation of x %F previousRotation %F\n",currentRotation,previousRotation);
NSLog(@"Angle:%F\n",(temp1*180)/M_PI);
temp1=temp1+newAngle;
//NSLog(@"Angle:%F\n",(temp1*180)/M_PI);
newTransform = CGAffineTransformRotate(newTransform, newAngle);
[self animateView:ViewRotationArrow toPosition:newTransform];
}
-(CGPoint)vectorFromPoint:(CGPoint)firstPoint toPoint:(CGPoint)secondPoint
{
CGPoint result;
CGFloat x = secondPoint.x-firstPoint.x;
CGFloat y = secondPoint.y-firstPoint.y;
result = CGPointMake(x, y);
return result;
}
-(void)animateView:(UIView *)theView toPosition:(CGAffineTransform) newTransform
{
//animating the rotator arrow...
[UIView setAnimationsEnabled:YES];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.0750];
ViewRotationArrow.transform = newTransform;
[UIView commitAnimations];
}
0
-(void)rotateView
{
//shape of eclipse
CAShapeLayer* circle = [[CAShapeLayer alloc] init];
CGMutablePathRef path = CGPathCreateMutable();
CGRect ViewRect = CGRectMake(self.view.bounds.size.width/2.8, (self.view.bounds.size.height-self.view.bounds.size.width/2)/2, self.view.bounds.size.width/4, self.view.bounds.size.width/2);
float midX = CGRectGetMidX(ViewRect);
float midY = CGRectGetMidY(ViewRect);
CGAffineTransform t = CGAffineTransformConcat(
CGAffineTransformConcat(
CGAffineTransformMakeTranslation(-midX, -midY),
CGAffineTransformMakeRotation(-1.57079633/0.99)),
CGAffineTransformMakeTranslation(midX, midY));
CGPathAddEllipseInRect(path, &t, ViewRect);
circle.path = path;
circle.frame = self.view.bounds;
circle.fillColor = [UIColor clearColor].CGColor;
circle.strokeColor = [UIColor greenColor].CGColor;
circle.lineWidth = 3.0f;
[self.view.layer addSublayer:circle];
CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
animation.duration = 0.0f;
animation.fromValue = [NSNumber numberWithFloat:0.0f];
animation.toValue = [NSNumber numberWithFloat:1.0f];
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
[circle addAnimation:animation forKey:@"strokeEnd"];
// rotateView red color
testView=[[UIView alloc]init];
testView.frame=CGRectMake(0, 0, 20, 20);
testView.backgroundColor=[UIColor redColor];
testView.userInteractionEnabled=YES;
testView.center=CGPathGetCurrentPoint(path);
testView.transform = CGAffineTransformMakeRotation(1.57079633);
[testView sizeToFit];
[self.view.layer addSublayer:testView.layer];
// view Animation
CAKeyframeAnimation* ViewAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
ViewAnimation.duration = 15.0f;
ViewAnimation.path = path;
ViewAnimation.rotationMode = kCAAnimationRotateAuto;
ViewAnimation.calculationMode = kCAAnimationCubicPaced;
//ViewAnimation.removedOnCompletion = NO;
[testView.layer addAnimation:ViewAnimation forKey:@"position"];
}
Verwandte Themen
- 1. Ziehen zum Drehen in iPhone-App
- 2. Bild mit Touch drehen, um Punkt in Android
- 3. Berühren und ziehen Bild in Android
- 4. Wie Bild mit Fixpunkt zusammen mit Touch in Android drehen
- 5. Kinetic js ziehen, droppen, vergrößern, verkleinern und drehen Bild
- 6. Wie ein qml Rechteck durch Ziehen drehen?
- 7. Erkennen Sie das spezifische iPhone/iPod Touch Modell in Javascript
- 8. Drehen Sie die Modellgruppe entsprechend der Richtung und dem Ort der Mausbewegung im Modell
- 9. Auto-Rotation, wenn das iPhone drehen
- 10. Wie ein Bild mit Touch
- 11. Sound Touch in iPhone
- 12. Eine direkte Möglichkeit, Bits entsprechend der Maske zu drehen
- 13. Drehen Sie ein Bild in Java
- 14. ziehen Reibungslos ein Sprite in cocos2d - iPhone
- 15. Protokoll Ziehen und Drehen in Windows
- 16. Ziehen Sie Twitter Profil Bild
- 17. Touch Pad Writer in iPhone
- 18. Bild drehen in Qt
- 19. Bild in HTA drehen
- 20. jScrollPane auf Touch-Geräten - Ziehen-Taste ist in umgekehrter Reihenfolge
- 21. So drehen Sie ein Bild im Canvas mit der Maus
- 22. Android zeichnen Linie und ziehen Sie es dann mit Touch
- 23. iPhone: So erstellen Sie ein dynamisches Bild Ziehen von Ala iPhone Symbol Neuanordnung
- 24. Ein Bild in Matplotlib drehen
- 25. iPhone dev - Manuelles Drehen der Ansicht
- 26. iPhone: Deaktivieren Sie Multi-Touch für App
- 27. Vergrößern Sie das Bild in UIImagePicker im iPhone
- 28. So drehen Sie ein Bild R-Raster
- 29. Bild drehen Wie Unten Bild
- 30. Ich möchte das Flip-Touch-Ereignis in iPhone implementieren
Dadurch werden alle Dinge, die u – NIKHIL
brauchen was ViewRotationArrow in dieser –
@krishna Es ist UIView, die auf seine eigene Mitte – NIKHIL