[英]How to use move and scale UIImagePickerController in iPhone?
I am new to iPhone development. 我是iPhone开发的新手。 I am working with image picker controller in which I want to move and scale the image that picked from the photo library, so I enabled the
allowsediting = yes
. 我正在使用图像选择器控制器,我想在其中移动并缩放从照片库中拾取的图像,因此我启用了
allowsediting = yes
。
And my picker did finish method: 我的选择器确实完成了方法:
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Access the uncropped image from info dictionary
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
self.imgForDisplay.image=[self scaleAndRotateImage:image];
self.imagePicker.allowsEditing = YES;
ImageDetailsViewController *imageDetailsVC = [[ImageDetailsViewController alloc] init];
imageDetailsVC.imagedisplay.image = self.imgForDisplay.image;
[picker pushViewController:imageDetailsVC animated:YES];
//[picker dismissModalViewControllerAnimated:YES];
}
and I push another view controller where I want to show the Image picked. 然后我推动另一个视图控制器,我想要显示拾取的图像。
Here I have two problems: 我有两个问题:
1) When I select the image, its navigating to another view without "move and scaling" screen but the image is now displayed in the ImageDetailsViewController when it navigates. 1)当我选择图像时,它导航到另一个视图而没有“移动和缩放”屏幕,但图像现在在导航时显示在ImageDetailsViewController中。
2) When I again navigate back and pick another image, now it shows the "move and scaling" screen. 2)当我再次导航并选择另一个图像时,现在它显示“移动和缩放”屏幕。 When I click the choose button, it is simply showing a white screen with out navigation bar.
当我单击选择按钮时,它只是显示一个带有导航栏的白色屏幕。
Is there any way to set the action for the choose button? 有没有办法为选择按钮设置操作?
I too face the same problem i solved it by using the by using the code, go through this it will be usefull. 我也面临同样的问题,我通过使用代码来解决它,通过这将是有用的。
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
self.lastChosenMediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([lastChosenMediaType isEqual:(NSString *)kUTTypeImage]) {
UIImage *chosenImage = [info objectForKey:UIImagePickerControllerEditedImage];
UIImage *shrunkenImage = shrinkImage(chosenImage, imageFrame.size);
self.image = shrunkenImage;
} else if ([lastChosenMediaType isEqual:(NSString *)kUTTypeMovie]) {
self.movieURL = [info objectForKey:UIImagePickerControllerMediaURL];
}
ImageSelectionView *imageSelectionVC = [[ImageSelectionView alloc] init];
imageSelectionVC.theImage = image;
[picker pushViewController:imageSelectionVC animated:YES];
imageSelectionVC.dismissDelegate =self;
// [picker dismissModalViewControllerAnimated:YES];
}
' “
-(void)updateDisplay {
if ([lastChosenMediaType isEqual:(NSString *)kUTTypeImage]) {
imageView.image = image;
imageView.hidden = NO;
moviePlayerController.view.hidden = YES;
} else if ([lastChosenMediaType isEqual:(NSString *)kUTTypeMovie]) {
[self.moviePlayerController.view removeFromSuperview];
self.moviePlayerController = [[MPMoviePlayerController alloc]
initWithContentURL:movieURL] ;
moviePlayerController.view.frame = imageFrame;
moviePlayerController.view.clipsToBounds = YES;
[self.view addSubview:moviePlayerController.view];
imageView.hidden = YES;
}
}
I think you would be better off presenting your picker modal like this: 我认为你最好提出这样的选择器模态:
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.allowsEditing = YES;
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
Then have your image displayed in the view of the viewcontoller that presented it. 然后让您的图像显示在呈现它的viewcontoller的视图中。
-(IBAction)Btn_AddImage:(id)sender
{
UIImagePickerController *Image_Picker=[[UIImagePickerController alloc]init];
Image_Picker.delegate=self;
Image_Picker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:Image_Picker animated:YES completion:Nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSData *Data=UIImageJPEGRepresentation([info objectForKey:@"UIImagePickerControllerOriginalImage"], 1);
UIImage *Cust_Image=[[UIImage alloc]initWithData:Data];
Profile_Image.image=Cust_Image;
[picker dismissViewControllerAnimated:YES completion:Nil];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissViewControllerAnimated:YES completion:Nil];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.