2013-07-20 137 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'動畫無關。 –