![](/img/trans.png)
[英]Quicklook/QLPreviewController shows a blank page instead of pdf on ios 8 but works fine on iOS7
[英]Quicklook/QLPreviewController, some problems with iOS 8 but everything works with iOS 7.1
我正在使用 QuickLook 查看 PDF 文件。
它在 iOS 7.1 中工作正常,但在 iOS 8 GM 中出現了一些問題。
圖片勝過文字,我想告訴你問題:
iOS 7.1 Xcode 6(工作正常)
使用 QuickLook 進行過渡(不會失敗)
頁面滾動,導航欄隱藏得很好
-------------------------------------------------- ------------------------
現在,iOS 8 GM 和 Xcode 6
使用 QuickLook 進行過渡...
頁面滾動,導航欄不隱藏,頁面指示器隱藏在導航欄后面
iPhone 模擬器、iPad 模擬器、iPhone 設備和 iPad 設備也有同樣的問題。
你可以在這里看到我的源代碼:
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)previewController
{
NSInteger numToPreview = 0;
if (currentSection == CVSectionConvocations)
numToPreview = self.convocation.convocations.count;
else if (currentSection == CVSectionAttachments)
numToPreview = self.convocation.attachements.count;
return numToPreview;
}
- (id)previewController:(QLPreviewController *)previewController previewItemAtIndex:(NSInteger)idx
{
PDF *pdf;
if (currentSection == CVSectionConvocations)
pdf = self.convocation.convocations[idx];
else if (currentSection == CVSectionAttachments)
pdf = self.convocation.attachements[idx];
return [pdf path];
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
// determine section
currentSection = (indexPath.section == 0 ? CVSectionConvocations : CVSectionAttachments);
PDF *pdf;
if (currentSection == CVSectionConvocations)
pdf = self.convocation.convocations[indexPath.row];
else if (currentSection == CVSectionAttachments)
pdf = self.convocation.attachements[indexPath.row];
if ([pdf isStored]) {
QLPreviewController *previewController = [[QLPreviewController alloc] init];
previewController.dataSource = self;
previewController.delegate = self;
previewController.currentPreviewItemIndex = indexPath.row;
[[self navigationController] pushViewController:previewController animated:YES];
} else {
[self displayMessage:@"Document not found" title:@"Oups !"];
}
}
謝謝你的幫助 ;)
我在轉換時遇到了同樣的問題。 我的解決方案是將 previewController 存儲在一個屬性中,並在我呈現的視圖控制器中的 viewDidLoad 中將其初始化一次。
我還必須在每次按下預覽控制器時將 currentPreviewItemIndex 設置為 0,盡管我當時只顯示一個文件。 如果我沒有設置值,默認情況下不會打開 zip 文件,並且預覽控制器會顯示一個“顯示內容”按鈕,這將打開一個遇到相同轉換問題的新預覽控制器。
我仍在嘗試解決不隱藏導航欄的問題。 在蘋果示例項目中,一切正常。 似乎以模態呈現導航控制器會導致我的項目出現問題。
編輯:
這對我來說絕對是一個錯誤。 導航欄的問題僅在導航控制器顯示為模態時才會出現。 在我看來,預覽控制器創建了一個新的導航控制器和一個新的導航欄。 這個隱藏在托管導航控制器的導航欄下。 此屏幕截圖很好地顯示了問題:
藍色突出顯示的欄是 self.navigationBar,藍色邊框屬於預覽控制器。 同樣,只有當導航控制器呈現模態時才會發生這種情況。
我的解決方法是將我的視圖控制器設置為導航控制器委托,並在按下預覽控制器后立即隱藏導航欄。 我只在 iOS 8.0 和 8.1 上測試了我的代碼。
- (void)viewDidLoad {
[super viewDidLoad];
self.previewController = [[QLPreviewController alloc] init];
self.previewController.delegate = self;
self.previewController.dataSource = self;
self.navigationController.delegate = self;
}
-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
// Workaround:
// If the previewController is pushed to a navigation controller which is presented modal, it appears that the preview controller adds a second navigation bar (and navigation controller).
// This results in a UI glitch that one nav bar is always visible. To prevent this we hide our navigation bar so that only the one owned by the preview controller is visible.
// Note that this only happends if the navigation controller is presented modal, thus it seems to be an iOS bug.
if (viewController == self.previewController) {
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
}
我最近已經能夠修復背景問題錯誤(動畫仍然斷斷續續)。
為了解決“黑色背景”問題,我在推送時設置了導航控制器視圖的自定義背景顏色。 當返回到我的視圖控制器時,我確保將原始背景顏色恢復為 nil。
- (void)viewWillApear:(BOOL)animated {
[super viewWillApear:animated];
self.navigationController.view.backgroundColor = nil;
// Optional - In order to ease the animation bug
self.view.alpha = 1.0;
}
- (void)viewWillDissapear:(BOOL)animated {
[super viewWillDissapear:animated];
self.navigationController.view.backgroundColor = [UIColor whiteColor];
// Optional - In order to ease the animation bug
[UIView animateWithDuration:0.35 animations:^{
self.view.alpha = 0.0;
}];
}
此代碼應該轉到您正在推送 QLPreviewController 的視圖控制器。
這個解決方案絕對是最好的解決方案,但希望它有所幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.