문제

QLPreviewController의 탐색 모음으로 사용자 정의 색상을 설정했습니다. 그러나 문제는 QLPreviewController의 탐색 막대의 어두운 색상을 원합니다. 심지어 탐색 모음 반투명 속성을 NO로 설정했습니다. 그러나 나는 그것이 왜 작동하지 않는지 알지 못한다

i

아래에서 원하세요.

여기에 이미지 설명

그러나이 이미지와 같은

여기에 이미지 설명을 입력하십시오

QLPreviewController *previewer = [[QLPreviewController alloc] init];
// Set data source
[previewer setDataSource:self];
[previewer setDelegate:self];
// Which item to preview
[previewer setCurrentPreviewItemIndex:index];
[previewer.view addGestureRecognizer:singleTap];
previewer.navigationController.navigationBar.translucent = NO;
previewer.navigationController.navigationBar.barTintColor = [UIColor redColor];
self.navigationController.navigationBar.translucent=NO;
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
   [self.navigationController pushViewController:previewer animated:TRUE ];
.

조차도이처럼 시도했지만

가 작동하지 않습니다.
    - (id <QLPreviewItem>)previewController: (QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
// Break the path into it's components (filename and extension)
// Use the filename (index 0) and the extension (index 1) to get path
//lblFileName.text=[strFileName stringByReplacingOccurrencesOfString:@"movefile" withString:@""];

// For navigation bar color and text attributes of navigation bar
for (id object in controller.childViewControllers)
{
    if ([object isKindOfClass:[UINavigationController class]])
    {
        UINavigationController *navController = object;
        navController.navigationBar.translucent=NO;
        navController.navigationBar.barTintColor = [UIColor redColor];;
        navController.toolbar.translucent=NO;
        navController.toolbar.barTintColor=[UIColor redColor];;
        [navController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil]];


    }
}

   NSString *strFilename=[[NSBundle mainBundle]pathForResource:@"final" ofType:@"png"];

return [NSURL fileURLWithPath:strFilename];
}
.

내가 어디로 가는지 제안 해주세요. 미리 감사드립니다

도움이 되었습니까?

해결책

주요 문제점은 탐색 모음의 반투명을 설정하려고하면 아직 탐색 스택에서 미리보기 컨트롤러를 푸시하지 않았습니다. 이 시점에서 미리보기 컨트롤러가 할당되고 인스턴스화되지만 뷰가로드되지 않았거나 뷰 계층 구조에 추가되지 않았으며 previewer.navigationController 값은 nil입니다. self.navigationController의 값은이 시점에서 nil이 아니라 여기에서 설정 한 반투명 속성은 미리보기 컨트롤러를 밀어 넣는 부작용으로 덮어 씁니다. 원하는 효과를 얻는 가장 쉬운 방법은 다음과 같이 명령문의 순서를 교환하는 것입니다.

[self.navigationController pushViewController:previewer animated:YES];
self.navigationController.navigationBar.translucent = NO;
.

탐색 모음의 반투명이 아니오로 설정되어 있지 않으면 미리보기 된 콘텐츠가 탐색 모음 아래에서 시작하여 원하는 것이 아닙니다. 해당 문제를 해결할 수있는 가장 쉬운 방법은 반투명 속성을 설정하는 것입니다. 미리보기 컨트롤러가 화면에 나타납니다. QLPreviewController 서브 클래스를 사용 하여이 작업을 수행 할 수 있습니다.

@interface PreviewController : QLPreviewController

@end

@implementation PreviewController

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    self.navigationController.navigationBar.translucent = NO;
}
.

탐색 스택에 미리보기 컨트롤러를 모드로 표시하는 대신 미리보기 컨트롤러를 표시 할 때 더 복잡해집니다. 이 경우 탐색 모음에 액세스하는 데 사용할 수있는 탐색 컨트롤러가 없으며 QLPreviewController의 내부 View 계층 구조에 의존해야합니다. 다음 코드는 iOS7에서 작동하지만 이후 버전에서는 깨질 수 있습니다.

[self presentViewController:previewController animated:YES completion:^{

    UIView *view = [[[previewController.view.subviews lastObject] subviews] lastObject];
    if ([view isKindOfClass:[UINavigationBar class]])
    {
        ((UINavigationBar *)view).translucent = NO;
    }

}];
.

다른 팁

서브 클래스가 필요하지 않습니다.이것을 시도하십시오 :

 QLPreviewController * ql = [[QLPreviewController alloc] init];
...
[self showViewController:ql sender:self];
ql.navigationController.navigationBar.translucent = NO;
ql.edgesForExtendedLayout = UIRectEdgeNone;
.

모형으로 표시하려면 PreviewController를 NavigationController에 넣으십시오.

UINavigationController * navi = [[UINavigationController alloc] initWithRootViewController:ql];
        ql.navigationController.navigationBar.translucent = NO;
        ql.edgesForExtendedLayout = UIRectEdgeNone;

        [self presentViewController:navi animated:YES completion:nil];
.

QLPreviewController를 사용하는 대신 Y WebView를 사용하여 웹 뷰에서 PDF를로드하면 버튼을 사용자 정의 해야하는 경우 QLPreviewController와 매우 유사합니다.

 NSURL *targetURL = [NSURL fileURLWithPath:path_pdf]; //path_pdf is pdf's path 
 NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
 [webview_pdf loadRequest:request];
.

잘 시도하십시오.

누구든지 QLPreviewController의 탐색 모음을 사용자 정의하려는 경우 UIViewController를 만들고 요구 사항에 따라 사용자 정의한 다음 QLPreviewController 객체를 만들고 자식보기 컨트롤러로 추가 할 수 있습니다.

이렇게하면 공유 버튼을 없애고 탐색 막대 색상을 사용자 정의 할 수 있습니다. 이것은 나를 위해 일하고 있습니다.

아시려면

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top