iphone 与 iPad在开发中的区别以及iPad中的UIPopoverController的使用
来源:互联网 发布:财经类报纸 知乎 编辑:程序博客网 时间:2024/06/08 01:08
共同点:用的都是IOS系统
不同点:
键盘:
iPad特有的API
屏幕方向的支持
设备支持的应用程序
设置内容控制器
- (id)initWithContentViewController:(UIViewController*)viewController;
// 如果不想使用初始化的内容控制器使用这个属性可以再次指定内容控制器
设置内容的尺寸
设置显示的位置
- (void)presentPopoverFromBarButtonItem:(UIBarButtonItem*)item permittedArrowDirections:(UIPopoverArrowDirection)arrowDirectionsanimated:(BOOL)animated;
- (void)presentPopoverFromRect:(CGRect)rect inView:(UIView*)view permittedArrowDirections:(UIPopoverArrowDirection)arrowDirectionsanimated:(BOOL)animated;
常用属性
@property (nonatomic,assign) id <UIPopoverControllerDelegate>delegate;
@property (nonatomic,readonly, getter=isPopoverVisible)BOOLpopoverVisible;
@property (nonatomic,readonly) UIPopoverArrowDirection popoverArrowDirection;
- (void)dismissPopoverAnimated:(BOOL)animated;
@property (nonatomic,copy) NSArray *passthroughViews;
示例:1、指向导航控制器的左边按钮
// 弹出菜单的单击事件- (IBAction)popMenu:(id)item { // 0.内容 HMMenuViewController *menu = [[HMMenuViewController alloc] init]; // 1.创建一个UIPopover UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:[[UINavigationController alloc] initWithRootViewController:menu]]; /** UIPopoverArrowDirectionUp = 1UL << 0, 指向上面 UIPopoverArrowDirectionDown = 1UL << 1, 指向下面 UIPopoverArrowDirectionLeft = 1UL << 2, 指向左边 UIPopoverArrowDirectionRight = 1UL << 3,指向右边 UIPopoverArrowDirectionAny = UIPopoverArrowDirectionUp | UIPopoverArrowDirectionDown | UIPopoverArrowDirectionLeft | UIPopoverArrowDirectionRight, 指向系统认为好的方向 UIPopoverArrowDirectionUnknown = NSUIntegerMax */ // 3.从哪里显示出来 --> 指向item [popover presentPopoverFromBarButtonItem:item permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; // 不允许popover还在显示的时候挂掉 // popover必须在消失的时候挂掉 (ios8以后就不需要了) self.popover = popover;}HMMenuViewController.m文件
#import "HMMenuViewController.h"@interface HMMenuViewController ()@property (nonatomic, strong) NSArray *titles;@end@implementation HMMenuViewController- (void)viewDidLoad { [super viewDidLoad]; self.titles = @[@"设置", @"清除缓存", @"退出", @"基本信息"]; self.title = @"菜单"; self.view.backgroundColor = [UIColor blueColor]; CGFloat w = 320; CGFloat h = self.titles.count * 44; self.preferredContentSize = CGSizeMake(w, h);// self.contentSizeForViewInPopover = CGSizeMake(w, h); }#pragma mark - Table view data source- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.titles.count;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *ID = @"cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID]; } cell.textLabel.text = self.titles[indexPath.row]; return cell;}- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ UIViewController *vc = [[UIViewController alloc] init]; vc.view.backgroundColor = [UIColor redColor]; [self.navigationController pushViewController:vc animated:YES];}
2、指向任意控件
- (IBAction)buttonClick:(UIButton *)btn { // 0.内容 HMColorsViewController *colors = [[HMColorsViewController alloc] init]; colors.delegate = self; // 1.创建 self.popover = [[UIPopoverController alloc] initWithContentViewController:colors]; self.popover.delegate = self; // 2.显示 [self.popover presentPopoverFromRect:btn.frame inView:btn.superview permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; // 3.设置哪里控件在popover显示出来的时候,仍旧可以跟用户进行交互 self.popover.passthroughViews = @[self.greenButton]; self.colorButton = btn;}#pragma mark - 颜色选择代理- (void)colorsViewController:(HMColorsViewController *)vc didSelectColor:(UIColor *)color{ self.colorButton.backgroundColor = color; // 关闭popover [self.popover dismissPopoverAnimated:YES];}#pragma mark - popover的代理- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController{// NSLog(@"popover销毁了");}
#import <UIKit/UIKit.h>@class HMColorsViewController;@protocol HMColorsViewControllerDelegate <NSObject>@optional- (void)colorsViewController:(HMColorsViewController *)vc didSelectColor:(UIColor *)color;@end@interface HMColorsViewController : UITableViewController@property (nonatomic, weak) id<HMColorsViewControllerDelegate> delegate;@endHMColorsViewController.m
- (void)viewDidLoad { [super viewDidLoad]; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}#pragma mark - Table view data source- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 30;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *ID = @"cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } cell.backgroundColor = [UIColor colorWithRed:arc4random_uniform(255)/255.0 green:arc4random_uniform(255)/255.0 blue:arc4random_uniform(255)/255.0 alpha:1.0]; return cell;}- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ if ([self.delegate respondsToSelector:@selector(colorsViewController:didSelectColor:)]) { UIColor *color = [tableView cellForRowAtIndexPath:indexPath].backgroundColor; [self.delegate colorsViewController:self didSelectColor:color]; }}
- iphone 与 iPad在开发中的区别以及iPad中的UIPopoverController的使用
- ipad 中的 UIPopoverController的使用
- iPad开发,UIPopoverController的使用
- iPhone与iPad开发的区别
- iPhone与iPad开发的区别
- iphone/iPad中的尺寸
- iPad开发 - UIPopoverController控制器
- iPad开发之UIPopoverController
- (一〇六)iPad开发之UIPopoverController的使用
- iPad如何使用UIPopoverController
- UIPopoverController和UIActionSheet在iPad中使用
- iPhone和iPad开发中的图标设置
- iPhone和iPad开发中的图标设置
- iPhone和iPad开发中的图标设置
- UIPopoverController 的使用方法 Ipad
- iphone和iPad开发的区别
- iOS开发 - 怎么让支持iPad/iPhone的app取消支持iPad或者iPhone中的一项
- Iphone 和 Ipad 开发 区别
- Python 线程同步与互斥
- 安卓中 自定义的对话框
- jsp小结11 - 9个内置对象04 out
- 修改ssh默认端口
- 第八周项目5 计数的模式匹配
- iphone 与 iPad在开发中的区别以及iPad中的UIPopoverController的使用
- Spark求数据集中同一主键记录中的最新数据
- 结构化图形绘制利器Graphviz
- 遗传算法--用python进化出chrome浏览器图标
- 点击通知启动App
- 二十年未见之数据造假现象,出路何在?
- Elasticsearch基础查询
- C#实现DDE的简便方法
- jsp小结12 - 9个内置对象05 page