2011-12-19 52 views
0

我如何構建一個應用程序,首先在空白的UIView中,然後允許用戶使用相機拍照,然後該圖片將出現在UiView上,用戶可以拖動和移動周圍的圖像。Iphone:出現並允許UIImage上的用戶交互

這裏是我的代碼,我到目前爲止,

-(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中的照片修改任何好的教程?

很多謝謝。

+2

難道你不認爲你是要求從同一個問題構建整個應用程序嗎?試着先實現一些東西。 – Sarah 2011-12-19 09:25:04

+0

我編輯了這些問題。我只知道如何啓動相機並將其放置在UIImage上,但我不知道如何拖動這張照片。非常感謝 – Clarence 2011-12-19 09:33:41

回答

0

藉助於uitouchmoved類,並使用相同的方法,您可以輕鬆地在uiview中移動圖像。請參閱this

相關問題