2016-09-27 1 views
0

나는 iOS을 처음 사용하며 UIActionSheet에 관한 문제에 봉착했습니다.ipad의 하단에 UIActionSheet를 어떻게 표시합니까?

내 코드는 다음과

-(IBAction)picimgbtnClick:(id)sender 
{ 
    UIActionSheet *popup = [[UIActionSheet alloc] initWithTitle:@"Profile Photo" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles: 
          @"Gallery", 
          @"Camera", 
          @"Remove Photo", 
          nil]; 


    popup.tag = 1; 
    [popup showInView:self.view]; 
} 

이 아이폰에 완벽하게 작동하지만 아이 패드에서이 작업을 실행할 때 UIActionSheet 중간에 나타납니다 같다 (아래 이미지 참조) 또한 취소 쇼하지 않습니다 버튼는 :

아이폰에

enter image description here

,이 같이 나타납니다 :

enter image description here

+0

ipad의 기본 동작입니다. 당신은 그것을 바꿀 수 없다 –

+0

@balkaran 그래서 그것에 대한 대안? – Muju

+1

당신은 UIPopoverController를 사용할 수 있습니다. –

답변

0

iPad의 하단에서 작업 시트를 표시 할 수 없으므로 알림을 표시하는 것입니다.

UIActionSheet 클래스는 iOS 8부터 사용되지 않으므로 더 이상 사용하지 않아야합니다. 대신 UIAlertController을 사용해야합니다.

Image of the alert

보여주는 지원되는 방법은 없습니다 :

UIAlertController *alert = 
    [UIAlertController alertControllerWithTitle:@"Profile Photo" 
             message:@"Select method of input" 
           preferredStyle:UIAlertControllerStyleAlert]; 

[alert addAction:[UIAlertAction actionWithTitle:@"Gallery" 
              style:UIAlertActionStyleDefault 
             handler:^void (UIAlertAction *action) { 
              NSLog(@"Clicked Gallery"); 
             }]]; 
[alert addAction:[UIAlertAction actionWithTitle:@"Camera" 
              style:UIAlertActionStyleDefault 
             handler:^void (UIAlertAction *action) { 
              NSLog(@"Clicked Camera"); 
             }]]; 
[alert addAction:[UIAlertAction actionWithTitle:@"Remove Photo" 
              style:UIAlertActionStyleDefault 
             handler:^void (UIAlertAction *action) { 
              NSLog(@"Clicked Remove Photo"); 
             }]]; 

[self presentViewController:alert animated:YES completion:nil]; 

이 아이폰에 경고 시트와 유사하다 경고로 옵션을 제공합니다 :이 거의 동일한 방식으로 작동 iPhone에서와 똑같은 방법 (하단에서부터). 당신이 그것에 대해 생각한다면, iPad의 여러 가지 방법으로 iPad의 바닥에 도달하는 것은 매우 어렵습니다. 센터가 훨씬 더 의미가 있습니다.

0
여기

방법 showInViewshowFromRectshowInView 방법하지만 당신은받지 않습니다 당신이 아이 패드에서 사용하는 것과 동일한 기능을 사용하여 cancel 옵션을 얻을 것이다 iPhone에 차이가 있습니다.

다음은 actionSheet 기원을 사용자 정의 할 수있는 몇 가지 방법은 이미지 아래에 볼 수 있습니다 :

enter image description here

UIActionSheet's showFromRect:inView:animated: 방법은 iPad에 사용될 예정이다. iPhone의 동작은 정의되지 않았습니다.

희망이 도움이됩니다.

+0

@vibhav 그러나 나는 그것을 넓히는 데 아벨이 아니다. 동일한 너비를 항상 보여줍니다. – Muju

+0

위의 너비를 설정하지 않아도됩니다. 단지 'showFromRect' 메소드를 사용하거나 [몇 분 내에 설정할 수 있습니다] (https://www.appcoda.com/uiactionsheet- uipopovercontroller-tutorial /) – vaibhav

+0

@vibhav 아이폰과 똑같이 표시해야합니다. – Muju

1

처음에는 UIActionSheet이 더 이상 사용되지 않으므로 최신 코드를 사용하십시오.

- (IBAction)capture:(UIButton *)sender { 

    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Title" message:@"Message" preferredStyle:UIAlertControllerStyleActionSheet]; 
    [alert addAction:[UIAlertAction actionWithTitle:@"Camera" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { 

     // Code for Cam 
    }]]; 
    [alert addAction:[UIAlertAction actionWithTitle:@"Gallery" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { 

     //Code for Gallery 
    }]]; 
    [alert addAction:[UIAlertAction actionWithTitle:@"Remove Photo" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { 

     //Code for removing photo 
    }]]; 
    [alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { 

    }]]; 
    [alert setModalPresentationStyle:UIModalPresentationPopover]; 

    UIPopoverPresentationController *popPresenter = [alert popoverPresentationController]; 
    popPresenter.sourceView = sender; 
    popPresenter.sourceRect = sender.bounds; // You can set position of popover 
    [self presentViewController:alert animated:TRUE completion:nil]; 
} 

@balkaran singh이 ipad의 기본 동작이라고 말했습니다. 너는 그것을 바꿀 수 없다. 그런 다음 사용자 정의 클래스를 구체화하고 애니메이션을 사용하여 필요한 UI를 정확하게 얻을 수 있습니다.

관련 문제