在PopOver中呈现一个Imagepicker

时间:2012-07-11 11:37:25

标签: iphone ios xcode uiimagepickercontroller uipopovercontroller

我一直在搜索多个图片选择器,我偶然发现AGImagePickerController,然后,我在iPad中进行编码,如何在popoverController alertView中呈现选择器?可能吗?或者我应该通过正常UIButton转移它?请帮忙。

AGImagePickerController *imagePickerController = [[AGImagePickerController alloc] initWithFailureBlock:^(NSError *error) {
        NSLog(@"Fail. Error: %@", error);

    if (error == nil) {
        NSLog(@"User has cancelled.");
        [self dismissModalViewControllerAnimated:YES];
    } else {

        // We need to wait for the view controller to appear first.
        double delayInSeconds = 0.015;
        dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
        dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
            [self dismissModalViewControllerAnimated:YES];
        });
    }

    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];

} andSuccessBlock:^(NSArray *info) {

    NSLog(@"Info: %@", info);
    [self.selectedPhotos setArray:info];

     }

    [self dismissModalViewControllerAnimated:YES];

    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
}];

// Show saved photos on top
imagePickerController.shouldShowSavedPhotosOnTop = YES;
imagePickerController.selection = self.selectedPhotos;

// Custom toolbar items
AGIPCToolbarItem *selectAll = [[AGIPCToolbarItem alloc] initWithBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:@"+ Select All" style:UIBarButtonItemStyleBordered target:nil action:nil] andSelectionBlock:^BOOL(NSUInteger index, ALAsset *asset) {
    return YES;
}];
AGIPCToolbarItem *flexible = [[AGIPCToolbarItem alloc] initWithBarButtonItem:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] andSelectionBlock:nil]; 
AGIPCToolbarItem *selectOdd = [[AGIPCToolbarItem alloc] initWithBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:@"+ Select Odd" style:UIBarButtonItemStyleBordered target:nil action:nil] andSelectionBlock:^BOOL(NSUInteger index, ALAsset *asset) {
    return !(index % 2);
}];
AGIPCToolbarItem *deselectAll = [[AGIPCToolbarItem alloc] initWithBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:@"- Deselect All" style:UIBarButtonItemStyleBordered target:nil action:nil] andSelectionBlock:^BOOL(NSUInteger index, ALAsset *asset) {
    return NO;
}];  
imagePickerController.toolbarItemsForSelection = [NSArray arrayWithObjects:selectAll, flexible, selectOdd, flexible, deselectAll, nil];
//    imagePickerController.toolbarItemsForSelection = [NSArray array];


imagePickerController.maximumNumberOfPhotos = 100;

[self presentModalViewController:imagePickerController animated:YES];

}

1 个答案:

答案 0 :(得分:1)

您应该通过Round Rect Button

使用此功能
self.popoverController = 
[[UIPopoverController alloc] initWithContentViewController:imagePickerController]; 

popoverController.delegate = self;

CGRect popoverRect = [self.view convertRect:[YOURBUTTON frame] 
                                   fromView:[YOURBUTTON superview]];    
popoverRect.size.width = MIN(popoverRect.size.width, 100);

[self.popoverController 
 presentPopoverFromRect:popoverRect 
 inView:self.view 
 permittedArrowDirections:UIPopoverArrowDirectionAny 
 animated:YES];

[popoverController setPopoverContentSize:CGSizeMake(1024, 500)];