Iphone:出现并允许用户在UIImage上进行交互

时间:2011-12-19 09:22:31

标签: iphone camera uiimage

我如何构建一个首先在空白UIView中的应用程序,然后允许用户使用相机拍照,然后该图片将出现在用户可以拖动和移动图像的UiView上。

这是我到目前为止的代码,

-(IBAction) getPhoto:(id) sender {
    UIImagePickerController * picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;

    if((UIButton *) sender == choosePhotoBtn) {
        picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    } else {
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        savebutton.hidden=NO;
    }

    [self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissModalViewControllerAnimated:YES];
    imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
}

-(void)imageSavedToPhotosAlbum:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
    NSString *message; NSString *title; 
    if (!error) {
        title = NSLocalizedString(@"Image Saved Successfully!", @"");
        message = NSLocalizedString(@"Tap Library and select this image.", @"");
    }

 else { title = NSLocalizedString(@"SaveFailedTitle", @""); message = [error description];
 } UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title 
                                                   message:message delegate:nil
                                         cancelButtonTitle:NSLocalizedString(@"OK", @"") otherButtonTitles:nil];
    [alert show]; [alert release];
    [message release]; [title release];}

-(IBAction) saveImage:(id)sender{
    UIImage *img = imageView.image;
    UIImageWriteToSavedPhotosAlbum(img, self, @selector(imageSavedToPhotosAlbum: didFinishSavingWithError: contextInfo:), nil);
}    

还有关于Xcode中照片修改的好教程吗?

非常感谢。

1 个答案:

答案 0 :(得分:0)

借助uitouchmoved类的帮助,使用相同的方法,您可以轻松地在uiview中移动图像。参见this