15

iPhone でポップオーバーを探していて、iOS 5 リーダー機能のようにしたい:

ここに画像の説明を入力

少し調査した結果、WEPopover と FPPopover を見つけましたが、この API 組み込みの iphone SDK のようなものがあるかどうかを調べています。

4

2 に答える 2

26

いくつかUIViewのカスタムアートワークを使用して作成し、次のようないくつかのボタンを使用して、ビューの上にアニメーションで「ポップオーバー」として表示できます。

UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(25, 25, 100, 50)]; //<- change to where you want it to show.

//Set the customView properties
customView.alpha = 0.0;
customView.layer.cornerRadius = 5;
customView.layer.borderWidth = 1.5f;
customView.layer.masksToBounds = YES;

//Add the customView to the current view
[self.view addSubview:customView];

//Display the customView with animation
[UIView animateWithDuration:0.4 animations:^{
    [customView setAlpha:1.0];
} completion:^(BOOL finished) {}];

#import <QuartzCore/QuartzCore.h>を使用する場合は、を忘れないでくださいcustomView.layer

于 2012-07-18T18:38:27.537 に答える
16

iOS8 以降、ポップオーバーを作成できるようになりました。これは、iPad と同じように iPhone でも同じです。これは、ユニバーサル アプリを作成する人にとって特に素晴らしいことです。したがって、個別のビューやコードを作成する必要はありません。

クラスとデモ プロジェクトは、 https ://github.com/soberman/ARSPopover から入手できます。

あなたがする必要があるのは、サブクラスであり、プロトコルUIViewControllerに準拠し、値とともに必要な設定を行うだけです:UIPopoverPresentationControllerDelegatemodalPresentationStyledelegate

// This is your CustomPopoverController.m

@interface CustomPopoverController () <UIPopoverPresentationControllerDelegate>

@end

@implementation CustomPopoverController.m

- (instancetype)init {
    if (self = [super init]) {
        self.modalPresentationStyle = UIModalPresentationPopover;
        self.popoverPresentationController.delegate = self;
    }
    return self;
}

- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
    return UIModalPresentationNone; //You have to specify this particular value in order to make it work on iPhone.
}

その後、表示したいメソッドで新しく作成したサブクラスをインスタンス化し、さらに 2 つの値を と に割り当てsourceViewますsourceRect。次のようになります。

CustomPopoverController *popoverController = [[CustomPopoverController alloc] init];
popoverController.popoverPresentationController.sourceView = sourceView; //The view containing the anchor rectangle for the popover.
popoverController.popoverPresentationController.sourceRect = CGRectMake(384, 40, 0, 0); //The rectangle in the specified view in which to anchor the popover.
[self presentViewController:popoverController animated:YES completion:nil];

これで、すてきなぼやけたポップオーバーが完成しました。

于 2015-05-23T22:01:53.933 に答える