2013-07-20 36 views
3

正如您在this video中看到的那样,每当我尝试裁剪或移动裁剪框时都会反弹回来。我找不到任何方法来做到这一点,我认为我的代码是正确的。我想如何做到这一点?移动和缩放反弹

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { 
    UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Error" 
                  message:@"Device has no camera" 
                 delegate:nil 
               cancelButtonTitle:@"OK" 
               otherButtonTitles: nil]; 
    [myAlertView show]; 
    } 
} 

- (IBAction)takePhoto:(UIButton *)sender { 
    UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 
    picker.delegate = self; 
    picker.allowsEditing = YES; 
    picker.sourceType = UIImagePickerControllerSourceTypeCamera; 
    [self presentViewController:picker animated:YES completion:NULL]; 
} 

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 
    UIImage *chosenImage = info[UIImagePickerControllerEditedImage]; 
    self.imageView.image = chosenImage; 
    [picker dismissViewControllerAnimated:YES completion:NULL]; 
} 
+0

我更新了我的答案,所以初学者可以理解。 – Arbitur

回答

0

如果图像是太远使用此方法将其动画回:

[UIView animateWithDuration: animations: completion:] 

动画:是块,它会改变如CGRects在持续时间,如果你想改变形象您添加的位置[image setRect:(CGRectMake(orginPosition.x, orginPosition.y, size.width, size.height))];

完成:是一个块,但不是必需的。

+0

对不起,你是什么意思...这段代码是什么意思? – user2590480

+0

你可以使用毕达哥拉斯定理,当你放开图像,如果毕达哥拉斯定理比你想要使用上面的方法更长...我不应该需要解释如何使用它,它非常简单 – Arbitur

+0

@arbitur,我不'相信你明白问题的问题。问题与'UIImagePickerController'编辑界面如何工作有关。它与'UIView'动画无关。 –