关闭

iPadNewProperty (2015-11-18 星期三)

标签: iPad的几个属性
111人阅读 评论(0) 收藏 举报
#import "AppDelegate.h"
#import "ViewController.h"


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    ViewController *rootVC = [[ViewController alloc] init];
    UINavigationController *naVC = [[UINavigationController alloc] initWithRootViewController:rootVC];
    self.window.rootViewController = naVC;
    return YES;
}
#import "ViewController.h"
@interface ViewController ()<UIPopoverControllerDelegate>
@property(nonatomic, strong)UIPopoverController *popOver;
@end


@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.view.backgroundColor = [UIColor orangeColor];

    UIViewController *contentVC = [[UIViewController alloc] init];

    //  初始化方法
    self.popOver = [[UIPopoverController alloc] initWithContentViewController:contentVC];
    self.popOver.popoverContentSize = CGSizeMake(300, 600);
    self.popOver.delegate = self;

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(BarButtonAction:)];

    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.backgroundColor = [UIColor purpleColor];
    button.frame = CGRectMake(100, 100, 100, 50);
    [self.view addSubview:button];
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];

    UIButton *Abutton = [UIButton buttonWithType:UIButtonTypeSystem];
    Abutton.backgroundColor = [UIColor purpleColor];
    Abutton.frame = CGRectMake(300, 100, 100, 50);
    [self.view addSubview:Abutton];
    [Abutton addTarget:self action:@selector(AbuttonAction:) forControlEvents:UIControlEventTouchUpInside];

    //  点击数组内的视图, 弹出窗口不会消失
    self.popOver.passthroughViews = @[Abutton];

}

- (void)AbuttonAction:(UIButton *)button {

}

#pragma mark    - popOverDelegate
//  发生改变的时候
- (void)popoverController:(UIPopoverController *)popoverController willRepositionPopoverToRect:(inout CGRect *)rect inView:(inout UIView *__autoreleasing   *)view {
    NSLog(@"变形");
}
//  消失
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
    NSLog(@"消失");
}
//  点击空白消失, 默认为YES
- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController {
    NSLog(@"~消失");
    return YES;
}

- (void)buttonAction:(UIButton *)button {

    //  第二种显示方法
    [self.popOver presentPopoverFromRect:button.bounds inView:button permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
}

- (void)BarButtonAction:(UIBarButtonItem *)button {

    //  第一种显示方法
    [self.popOver presentPopoverFromBarButtonItem:button permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
...
@end
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:4262次
    • 积分:393
    • 等级:
    • 排名:千里之外
    • 原创:36篇
    • 转载:1篇
    • 译文:0篇
    • 评论:0条
    文章存档