0

我一直在尋找一個多圖片選擇器,並且我偶然發現了AGImagePickerController,但是隨後,我在iPad上編碼,我如何在popoverControlleralertView中展示選取器?可能嗎?或者我應該通過正常的UIButton轉移?請幫忙。在PopOver中展示圖片選擇器

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

Popovers一般不應從警報意見提出。他們應該從他們的箭頭將指向的按鈕/控件中呈現出來。 – Accatyyc 2012-07-11 11:43:16

+0

哦,這就是爲什麼,那麼我該如何在popOver中呈現這個選擇器? – Bazinga 2012-07-11 11:45:23

回答

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)]; 
+0

已經測試過。它工作正常。謝謝。 – Bazinga 2012-07-12 08:27:16