2015-01-21 1 views
0

Apple은 iOS8부터 UIPopoverController의 태도를 변경하는 것으로 보입니다.iOS8 : UIPopoverController를 표시하지 않지만 iOS7은 정상입니다.

아래 코드를 확인하십시오. addSubview 다음에 UIPopoverController를 표시하려고합니다. iOS6 및 iOS7은 문제가 없지만 iOS8에는 표시되지 않습니다.

가능한 이유를 제안 해주세요. 어떤 도움을 주시면 감사하겠습니다.

enter image description here

enter image description here

갱신 1

- (IBAction)tapButton:(id)sender { 

    SampleView *sampleView = [[SampleView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 
                      [UIScreen mainScreen].bounds.size.width, 
                      [UIScreen mainScreen].bounds.size.height)]; 
    sampleView.backgroundColor = [UIColor blueColor]; 
    sampleView.alpha = 0.5; 

    sampleView.label = [[UILabel alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/2, 
                   [UIScreen mainScreen].bounds.size.height/2, 
                   200.0f, 20.0f)]; 
    sampleView.label.text = @"SAMPLE TEXT"; 
    sampleView.label.textColor = [UIColor redColor]; 
    [sampleView addSubview:sampleView.label]; 

    [self.view.window addSubview:sampleView]; 

    if (!self.popover) { 
     UIViewController *vc = [[UIViewController alloc] init]; 
     vc.view.backgroundColor = [UIColor redColor]; 
     vc.preferredContentSize = CGSizeMake(200, 300); 
     self.popover = [[UIPopoverController alloc] initWithContentViewController:vc]; 
    } 

    // On iOS7 is OK but not show on iOS8 
    [self.popover presentPopoverFromRect:CGRectMake(200, 100, 0, 0) 
            inView:sampleView.label 
       permittedArrowDirections:UIPopoverArrowDirectionUp 
           animated:YES]; 
} 

는 :

이 질문의 대답 하였다.

in iOS8: UIPopoverController presentPopoverFromRect not work for keyWindow any more

이 코드를 업데이트됩니다.

enter image description here

[self.popover presentPopoverFromRect:CGRectMake(200, 100, 0, 0) 
            inView:self.view 
       permittedArrowDirections:UIPopoverArrowDirectionUp 
           animated:YES]; 

는 지금까지 내가 검사로, keyWindos 및 self.view.window은 같은 것 같다.

NSLog(@"%@", [UIApplication sharedApplication].keyWindow); 
NSLog(@"%@", self.view.window); 

그러나이 경우는 완전한 해결책이 아닙니다. 추가 된 하위 뷰에 대한보기를 제어하려고합니다.

갱신 2 :

은 내가 iOS8의에 UIPopoverPresentationController를 사용할 필요가 있다고 생각한다.

- (IBAction)tapButton:(id)sender { 

    // View 
    SampleView *sampleView = [[SampleView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 
                      [UIScreen mainScreen].bounds.size.width, 
                      [UIScreen mainScreen].bounds.size.height)]; 
    sampleView.backgroundColor = [UIColor blueColor]; 
    sampleView.alpha = 0.5; 

    // Label 
    sampleView.label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 20.0f)]; 
    sampleView.label.text = @"SAMPLE TEXT"; 
    sampleView.label.textColor = [UIColor redColor]; 
    [sampleView addSubview:sampleView.label]; 

    // View Controller 
    UIViewController *viewController = [[UIViewController alloc] init]; 
    viewController.modalPresentationStyle = UIModalPresentationPopover; 
    viewController.view = sampleView; 

    // UIPopoverPresentationController 
    UIPopoverPresentationController *presentationController = viewController.popoverPresentationController; 
    [presentationController setDelegate:self]; 
    presentationController.permittedArrowDirections = 0; 
    presentationController.sourceView = [[UIApplication sharedApplication] keyWindow]; 
    presentationController.sourceRect = [[UIApplication sharedApplication] keyWindow].bounds; 

    [viewController setPreferredContentSize:CGSizeMake(320, 480)]; 
    [self presentViewController:viewController animated:YES completion:nil]; 

    if (!self.popover) { 
     UIViewController *vc = [[UIViewController alloc] init]; 
     vc.view.backgroundColor = [UIColor redColor]; 
     vc.preferredContentSize = CGSizeMake(200, 300); 
     vc.modalPresentationStyle = UIModalPresentationPopover; 
     self.popover = [[UIPopoverController alloc] initWithContentViewController:vc]; 
     self.popover.delegate = self; 
    } 

    [self.popover presentPopoverFromRect:CGRectMake(300, 300, 0, 0) 
            inView:viewController.view 
       permittedArrowDirections:UIPopoverArrowDirectionUp 
           animated:YES]; 
} 

enter image description here

갱신 3 나는 dispatch_async을 사용하지만했다. 어떤 경우에는 dispatch_async가이 경우에 효과적이라고합니다. dispatch_async는 매우 간단한 해결책입니다. 나는 그것을 사용하는 것을 선호한다. dispatch_async를 사용하여 내 문제를 해결할 수 있다면 코드를 첨부 할 수있어서 고맙겠습니다.

- (IBAction)tapButton:(id)sender { 

    SampleView *sampleView = [[SampleView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 
                      [UIScreen mainScreen].bounds.size.width, 
                      [UIScreen mainScreen].bounds.size.height)]; 
    sampleView.backgroundColor = [UIColor blueColor]; 
    sampleView.alpha = 0.5; 

    sampleView.label = [[UILabel alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/2, 
                   [UIScreen mainScreen].bounds.size.height/2, 
                   200.0f, 20.0f)]; 
    sampleView.label.text = @"SAMPLE TEXT"; 
    sampleView.label.textColor = [UIColor redColor]; 
    [sampleView addSubview:sampleView.label]; 

    [self.view.window addSubview:sampleView]; 

    if (!self.popover) { 
     UIViewController *vc = [[UIViewController alloc] init]; 
     vc.view.backgroundColor = [UIColor redColor]; 
     vc.preferredContentSize = CGSizeMake(200, 300); 
     self.popover = [[UIPopoverController alloc] initWithContentViewController:vc]; 
    } 

    // I tried this but not worked. 
    dispatch_async(dispatch_get_main_queue(), ^{ 
     [self.popover presentPopoverFromRect:CGRectMake(200, 100, 0, 0) 
             inView:sampleView.label 
        permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; 
    }); 
} 

답변

3

시험 후 편집이 내 코드, 그것은 또는 dispatch_async없이 작동됩니다

 
    dispatch_async(dispatch_get_main_queue(), ^{ 
    [self.popover presentPopoverFromRect:CGRectMake(200, 100, 0, 0) inView:sampleView.label permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; 
}); 

아이폰 OS 8 다음을 수행합니다.

 
self.popover = [[UIPopoverController alloc] initWithContentViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"second"]]; 
    dispatch_async(dispatch_get_main_queue(), ^{ 
     [self.popover presentPopoverFromRect:self.button.frame inView:self.button permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; 
    }); 
+0

감사합니다. 나는 그것을 시도했지만 효과가 없습니다. 내 질문의 Update3을 참조하십시오. 어떤 이들은 dispatch_async가 효과적이지만 제 경우에는 효과가 없다고 말합니다. – zono

+0

dispatch_async가 정상적으로 작동합니까? – zono

관련 문제