1
我知道如何打開照片庫,現在我想選擇其中一個圖像並將其放在UIImageView上,有什麼辦法可以做到嗎?[iOS]從照片庫中選擇圖片
我知道如何打開照片庫,現在我想選擇其中一個圖像並將其放在UIImageView上,有什麼辦法可以做到嗎?[iOS]從照片庫中選擇圖片
你有沒有提到照片庫意味着什麼?
下面一個是從照片庫
-(void)photoLibraryAction
{
NSLog(@"image");
if(picker!=nil){
[picker dismissModalViewControllerAnimated:YES];
[test dismissPopoverAnimated:YES];
picker.delegate=nil;
picker=nil;
test.delegate=nil;
test=nil;
}
picker= [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
picker.delegate=(id)self;
NSLog(@"%@",picker);
if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone)
{
[self presentModalViewController:picker animated:YES];
}
// [self pre
else if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad)
{
UIPopoverController *popImageLibrary=[[UIPopoverController alloc]initWithContentViewController:picker];
test=popImageLibrary;
test.delegate=(id)self;
[test presentPopoverFromRect:CGRectMake(240, 730, 400, 0) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
}
訪問圖像並設置爲代表圖像選擇器
picker.delegate=(id)self;
然後使用委託方法
- (void)imagePickerController:(UIImagePickerController *)albumPicker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone || albumPicker.sourceType==UIImagePickerControllerSourceTypeCamera)
{
self.imageData=[info objectForKey:@"UIImagePickerControllerOriginalImage"];
[albumPicker dismissModalViewControllerAnimated:YES];
}
else
{
yourImageView.image=[info objectForKey:@"UIImagePickerControllerOriginalImage"];
[test dismissPopoverAnimated:YES];
}
}
代碼