旋转,移动,frame的混用,

 UIRotationGestureRecognizer *rotationRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)];

    [rotationRecognizer setDelegate:self];

    [self.view addGestureRecognizer:rotationRecognizer];

    

    UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];

    [panRecognizer setMinimumNumberOfTouches:1];

    [panRecognizer setMaximumNumberOfTouches:1];

    [panRecognizer setDelegate:self];

    [self.view addGestureRecognizer:panRecognizer];

// 旋转

-(void)rotate:(id)sender {

    

    if([(UIRotationGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) {

        

        _lastRotation = 0.0;

        return;

    }

    

    CGFloat rotation = 0.0 - (_lastRotation - [(UIRotationGestureRecognizer*)sender rotation]);

    

    CGAffineTransform currentTransform = _imageView.transform;

    CGAffineTransform newTransform = CGAffineTransformRotate(currentTransform,rotation);

    

    [_imageView setTransform:newTransform];

    

    _lastRotation = [(UIRotationGestureRecognizer*)sender rotation];

    

}


// 移动

-(void)move:(id)sender {

    

    CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender translationInView:self.view];

    

    if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan) {

        

        _startPoint = translatedPoint;

        _firstX = [_imageView center].x;

        _firstY = [_imageView center].y;

    }

    else if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateChanged)

    {

        _changePoint = translatedPoint;

        

        _imageView.transform = CGAffineTransformTranslate(_imageView.transform, _changePoint.x - _startPoint.x, _changePoint.y - _startPoint.y);


        _startPoint = _changePoint;

    }

}


// 改变 frame 的 height

- (IBAction)declineHH:(id)sender

{

    CGAffineTransform aaaaaTransform = _imageView.transform;

    

    [_imageView setTransform:CGAffineTransformIdentity];

    

    _imageView.frame = CGRectMake(_imageView.frame.origin.x, _imageView.frame.origin.y, _imageView.frame.size.width, _imageView.frame.size.height - 2);

    

    [_imageView setTransform:aaaaaTransform];

}

// 改变frame width

- (IBAction)declineWW:(id)sender

{

    CGAffineTransform aaaaaTransform = _imageView.transform;

    

    [_imageView setTransform:CGAffineTransformIdentity];

    

    _imageView.frame = CGRectMake(_imageView.frame.origin.x, _imageView.frame.origin.y, _imageView.frame.size.width - 2, _imageView.frame.size.height);

    

    [_imageView setTransform:aaaaaTransform];

}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值