voleibol toque saque remate metodologia imagenes golpe ejercicios dedos antebrazos antebrazo alto iphone image rotation

iphone - saque - Gire la imagen en el centro con un toque de dedo



saque alto en voleibol (1)

Quiero rotar la imagen de abajo en un punto central usando un toque de dedo ...

Y quiero mostrar el valor de la imagen con la etiqueta cuando gire la imagen usando el tacto.

He hecho la rotación de la imagen pero el problema es cómo establecer el valor de la imagen según la rotación.

El ángulo de rotación aumenta, así que no puedo establecer el valor.

¿Alguien puede ayudarme?

El código está debajo

float fromAngle = atan2(firstLoc.y-imageView.center.y, firstLoc.x-imageView.center.x); NSLog(@"From angle:%f",fromAngle); float toAngle = atan2( currentLoc.y-imageView.center.y, currentLoc.x-imageView.center.x); NSLog(@"to Angle:%f",toAngle); // So the angle to rotate to is relative to our current angle and the // angle through which our finger moved (to-from) float newAngle =angle+(toAngle-fromAngle); NSLog(@"new angle:%.2f",newAngle); CGAffineTransform cgaRotate = CGAffineTransformMakeRotation(newAngle); imageView.transform=cgaRotate; angle = newAngle;

Alguien puede ayudarme ?


No estaba totalmente seguro de lo que estabas buscando; pero prueba este código

Si crea un nuevo proyecto de Aplicación basado en Vista llamado ''Rotación'' y reemplaza el código en RotationViewController.h y .m para lo siguiente, obtendrá un bloque verde que puede rotar usando sus cálculos. Puedes reemplazar el bloque verde UIView con tu UIImageView, o cualquier otra cosa que quieras girar.

RotationViewController.h

#import <UIKit/UIKit.h> @interface RotationViewController : UIViewController { UIView* m_block; UILabel* m_label; CGPoint m_locationBegan; float m_currentAngle; } - (float) updateRotation:(CGPoint)_location; @end

RotationViewController.m

#import "RotationViewController.h" double wrapd(double _val, double _min, double _max) { if(_val < _min) return _max - (_min - _val); if(_val > _max) return _min - (_max - _val); return _val; } @implementation RotationViewController - (void)viewDidLoad { [super viewDidLoad]; CGRect blockFrame = CGRectMake(0, 0, 200, 200); m_block = [[UIView alloc] initWithFrame:blockFrame]; m_block.backgroundColor = [UIColor greenColor]; m_block.center = self.view.center; [self.view addSubview:m_block]; [m_block release]; CGRect labelFrame = CGRectMake(0, 0, 320, 30); m_label = [[UILabel alloc] initWithFrame:labelFrame]; m_label.text = @"Loaded"; [self.view addSubview:m_label]; } - (void) touchesBegan:(NSSet *)_touches withEvent:(UIEvent *)_event { UITouch* touch = [_touches anyObject]; CGPoint location = [touch locationInView:self.view]; m_locationBegan = location; } - (void) touchesMoved:(NSSet *)_touches withEvent:(UIEvent *)_event { UITouch* touch = [_touches anyObject]; CGPoint location = [touch locationInView:self.view]; [self updateRotation:location]; } - (void) touchesEnded:(NSSet *)_touches withEvent:(UIEvent *)_event { UITouch* touch = [_touches anyObject]; CGPoint location = [touch locationInView:self.view]; m_currentAngle = [self updateRotation:location]; } - (float) updateRotation:(CGPoint)_location { float fromAngle = atan2(m_locationBegan.y-m_block.center.y, m_locationBegan.x-m_block.center.x); float toAngle = atan2(_location.y-m_block.center.y, _location.x-m_block.center.x); float newAngle = wrapd(m_currentAngle + (toAngle - fromAngle), 0, 2*3.14); CGAffineTransform cgaRotate = CGAffineTransformMakeRotation(newAngle); m_block.transform = cgaRotate; int oneInFifty = (newAngle*50)/(2*3.14); m_label.text = [NSString stringWithFormat:@"Angle: %f 1in50: %i", newAngle, oneInFifty]; return newAngle; } @end