Подтвердить что ты не робот

Как создать popover в приложении iPhone?

Я ищу popover в iPhone, и я хочу сделать его как функцию iOS 5 Reader:

enter image description here

После небольшого исследования я нашел WEPopover и FPPopover, но я смотрю, есть ли что-то вроде этого API встроенного iphone SDK.

4b9b3361

Ответ 1

Вы можете сделать UIView с некоторыми пользовательскими обложками и отобразить его с анимацией поверх вашего представления как "popover" с некоторыми кнопками:

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.

Ответ 2

Так как iOS8 теперь может создавать popovers, это будет одинаково на iPhone, как на iPad, что было бы особенно удивительно для тех, кто делает универсальные приложения, поэтому нет необходимости создавать отдельные представления или код.

Вы можете получить класс, а также демонстрационный проект здесь: https://github.com/soberman/ARSPopover

Все, что вам нужно сделать, это подкласс UIViewController, соответствовать протоколу UIPopoverPresentationControllerDelegate и установить желаемый modalPresentationStyle вместе со значением delegate:

// 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.
}

Затем создайте новый созданный подкласс в методе, из которого вы хотите его показать, и назначьте еще два значения 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];

И там у вас есть, хороший, аккуратный размытый popover.