ios - 移动和缩放反弹

标签 ios objective-c uiviewanimation

正如您在 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];
}

最佳答案

如果图像距离太远,请使用此方法将其动画化:

[UIView animateWithDuration: animations: completion:]

动画:是一个 block ,它会在一段时间内改变,例如 CGRects,如果你想改变你添加的图像位置 [image setRect:(CGRectMake(orginPosition.x, orginPosition.y, size.width,尺寸.高度))];

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

关于ios - 移动和缩放反弹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17762574/

相关文章:

ios - UIView 动画/旋转时 UIButton 触摸位置不准确

ios - 如何判断 PDFDocument 是否已加载到 PDFView

ios - 使用来自 API 的 JSON 填充单元格

ios - 如何启用xcode预编译的源文件

ios - 如何使用AVPlayer中的缓存播放ts文件?

ios - 如何确保具有重复动画的 UITableView 标题单元格 subview 在 reloadData、用户滚动等之后继续动画?

ios - Objective-C 如何正确实现协议(protocol)或其他解决方案

ios - 切换方向时如何正确定位我的 ScrollView 图像?

objective-c - 如何从 UIColor 获取反色?

ios - UIImageView 框架没有按预期进行动画处理(大小和原点)