Ios 如何从目标c中的定位点使用滑动手势旋转图像?

Ios 如何从目标c中的定位点使用滑动手势旋转图像?,ios,objective-c,xcode,Ios,Objective C,Xcode,在这里,我旋转一个给定角度的图像。但是我想从一个定位点旋转一个带有滑动手势的图像 - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. //circleName is an UIImageView IBoutlet _circleName

在这里,我旋转一个给定角度的图像。但是我想从一个定位点旋转一个带有滑动手势的图像

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.

        //circleName is an UIImageView IBoutlet

        _circleNames=@"Squre.png";
        _showCircle=[UIImage imageNamed:_circleNames];
        _circleView.image=_showCircle;


       // Here I am setting anchor point 
         _circleView.layer.anchorPoint=CGPointMake(0.5, 1.0);

        //here I am setting animation

        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:6];
        [UIView setAnimationRepeatCount:0];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

      //rotate 170 degree angle
        _circleView.transform=CGAffineTransformRotate(_circleView.transform,170);
  [UIView commitAnimations];
}

可以使用此选项将图像旋转90度

CGAffineTransformMakeRotation(CGFloat(M_PI_2))

如果要随手指动态旋转图像,必须使用
uipangestureerecognizer
(而不是
uisweegestureerecognizer
)。它会在您提供的反复调用的选择器中指出您的手指

更新

您可以使用以下代码:

#import "ViewController.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIView* rotView;

@end

@implementation ViewController {

    UIPanGestureRecognizer* _panGesture;
    float _deltaAngle;
    CGAffineTransform _startTransform;
    CGPoint _prevPoint;
}

- (void) viewDidLoad {

    [super viewDidLoad];

    _panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(rotateItem:)];
    _panGesture.delegate = self;
    [self.rotView addGestureRecognizer:_panGesture];
}

- (void) rotateItem:(UIPanGestureRecognizer *)recognizer {

    CGPoint currPoint = [recognizer locationInView:self.view];

    CGPoint center = recognizer.view.center;

    CGFloat ang = atan2f(currPoint.y - center.y, currPoint.x - center.x) - atan2f(_prevPoint.y - center.y, _prevPoint.x - center.x);

    _prevPoint = [recognizer locationInView:self.view];

    _deltaAngle += ang;

    self.rotView.transform = CGAffineTransformRotate(_startTransform, _deltaAngle);
}

- (BOOL) gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)recognizer {

    _startTransform = self.rotView.transform;

    return YES;
}

@end
更新2

我在github上创建了带有示例的类(和类别):

170度?170英寸弧度更有可能。可能是:)我是iOS新手。谢谢。谢谢。但当我触摸手指时,我想从一个定位点移动/旋转图像。如果您提供代码来帮助我,我将不胜感激。我已成功地从您的更新代码中旋转了一个项目/图像视图。但我的任务是在旋转项目时显示四个图像或逐个移动这些图像。@Md.AshikMahmud只需在一个视图中放置一个图像,并在Interface builder中将此视图的自定义类设置为UIRatatableView(并确保rotatable属性设置为YES)。如果您在github上使用我的库,则无其他代码(请参阅update2)。谢谢。但我的任务正在以某种方式更改。这是我的新问题,请在这里发表评论,我也尝试了您的类,但IB_DESIGNABLE中存在错误。我的Xcode不知道这一点。