正确的解决方案是来自@LuisCien
我在这里补充一点,我发现它在将 UIScrollView 与 MPMediaPickerController 一起使用时很有用,所以:
- (void)fixViewFrameBoundSize {
CGRect contentsFrame = self.view.frame;
CGSize boundsSize = self.view.bounds.size;
if (contentsFrame.size.height < boundsSize.height) {
contentsFrame.origin.y = (boundsSize.height - contentsFrame.size.height) / 2.0f;
} else {
contentsFrame.origin.y = 0.0f;
}
[self.view setFrame:contentsFrame];
}
和
- (void)mediaPickerDidCancel:(MPMediaPickerController *)mediaPicker {
[self dismissViewControllerAnimated:YES completion:^{
dispatch_async(dispatch_get_main_queue(), ^{
[self fixViewFrameBoundSize];
});
}];
}
对于选定的项目回调也是如此:
[self dismissViewControllerAnimated:YES
completion:^{
//LP : get item url and play
dispatch_async(dispatch_get_main_queue(), ^{
[self fixViewFrameBoundSize];
});
MPMediaItem *item = [collection representativeItem];
当您有一个带有 UIView 的 XIB 时,此解决方案效果很好,并且您在 UISCrollView 中对其进行转换,如下所示:
- (void)scrollViewMakeScrollable {
CGSize scrollableSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height+44.0);
[((UIScrollView*)self.view) setContentSize:scrollableSize];
[((UIScrollView*)self.view) setAlwaysBounceHorizontal:NO];
[((UIScrollView*)self.view) setAlwaysBounceVertical:NO];
self.automaticallyAdjustsScrollViewInsets = NO;
}
所以通常当你这样做时
- (void) viewDidLoad {
[super viewDidLoad];
[self scrollViewMakeScrollable];