CGRect btnF = CGRectMake(200, 200, 100, 50);
UIButton *button = [[UIButton alloc] initWithFrame:btnF];
button.backgroundColor = [[UIColor brownColor] colorWithAlphaComponent:0.5];
[self.view addSubview:button];
[button addTarget:self action:@selector(present:) forControlEvents:UIControlEventTouchUpInside];
UIPopoverController
- (void)present:(UIButton *)sender {
FirstViewController *cityListVC = [[FirstViewController alloc] init];
//将cityListVC塞进_popover
_popover = [[UIPopoverController alloc] initWithContentViewController:cityListVC];
//设置_popover的尺寸
_popover.popoverContentSize = CGSizeMake(100, 100);
//设置代理
_popover.delegate = self;
//展示_popover
[_popover presentPopoverFromRect:button.bounds inView:button permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
UIPopoverPresentationController
- (void)present:(UIButton *)sender {
cityListVC.preferredContentSize = CGSizeMake(100, 100);
cityListVC.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *popController = [cityListVC popoverPresentationController];
popController.sourceView = sender;
popController.sourceRect = sender.bounds;
popController.delegate = self;
popController.permittedArrowDirections = UIMenuControllerArrowDown;
[self presentViewController:cityListVC animated:YES completion:nil];
}
- (void)present:(UIButton *)sender {
_hallManagerNav = [[UINavigationController alloc] initWithRootViewController:cityListVC];
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"关闭" style:(UIBarButtonItemStylePlain) target:self action:@selector(closePresentCtr)];
[cityListVC.navigationItem setRightBarButtonItem:item];
//弹出时动画风格
_hallManagerNav.modalTransitionStyle =UIModalTransitionStyleCrossDissolve;
//弹出风格
_hallManagerNav.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:_hallManagerNav animated:YES completion:nil];
}
typedef NS_ENUM(NSInteger, UIModalTransitionStyle) {
UIModalTransitionStyleCoverVertical = 0,
UIModalTransitionStyleFlipHorizontal __TVOS_PROHIBITED,
UIModalTransitionStyleCrossDissolve,
UIModalTransitionStylePartialCurl NS_ENUM_AVAILABLE_IOS(3_2) __TVOS_PROHIBITED,
};
typedef NS_ENUM(NSInteger, UIModalPresentationStyle) {
UIModalPresentationFullScreen = 0,
UIModalPresentationPageSheet NS_ENUM_AVAILABLE_IOS(3_2) __TVOS_PROHIBITED,
UIModalPresentationFormSheet NS_ENUM_AVAILABLE_IOS(3_2) __TVOS_PROHIBITED,
UIModalPresentationCurrentContext NS_ENUM_AVAILABLE_IOS(3_2),
UIModalPresentationCustom NS_ENUM_AVAILABLE_IOS(7_0),
UIModalPresentationOverFullScreen NS_ENUM_AVAILABLE_IOS(8_0),
UIModalPresentationOverCurrentContext NS_ENUM_AVAILABLE_IOS(8_0),
UIModalPresentationPopover NS_ENUM_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED,
UIModalPresentationNone NS_ENUM_AVAILABLE_IOS(7_0) = -1,
};
网友评论