iPad是一款蘋果公司于2010年發(fā)布的平板電腦
定位介于蘋果的智能手機iPhone和筆記本電腦MacBook產(chǎn)品之間
跟iPhone一樣,搭載的是iOS操作系統(tǒng)
iPhone和iPad開發(fā)的區(qū)別
屏幕的尺寸 \分辨率
UI元素的排布 \設(shè)計
鍵盤
API
屏幕方向的支持
… …
1.iPhone&iPad開發(fā)異同
1.1鍵盤
iPad的虛擬鍵盤多了個退出鍵盤的按鈕


1.2iPad特有API
iPad多了一些特有的類,比如:
UIPopoverController // 膨松餅
UISplitViewController // 分割線
… …


1.3共有API的差異
有些API在iPhone和iPad都能用,但是顯示效果是有差異的,比如UIActionSheet
1.4屏幕方向的支持


1.5橫豎屏支持
一般,iPhone應(yīng)用就一種屏幕方向,要么豎屏,要么橫屏(游戲)
其次,蘋果官方建議:iPad應(yīng)用最好同時支持橫屏、豎屏兩種方向
1.6開發(fā)細節(jié)

設(shè)備支持的應(yīng)用程序
iPhone上只能運行iPhone程序
iPad上能夠運行iPhone \ iPad程序
開發(fā)過程
iPhone和iPad開發(fā)的流程是一致的
iPhone開發(fā)的技術(shù)基本都能用在iPad上
2.Modal
在iPhone開發(fā)中
Modal是一種常見的切換控制器的方式
默認(rèn)是從屏幕底部往上彈出,直到完全蓋住后面的內(nèi)容為止
在iPad開發(fā)中
Modal的使用頻率也非常高
對比iPhone開發(fā),Modal在iPad開發(fā)中多了一些用法
呈現(xiàn)樣式 : Modal出來的控制器,最終顯示出來的樣子
Modal常見有4種呈現(xiàn)樣式
UIModalPresentationFullScreen :全屏顯示(默認(rèn))
UIModalPresentationPageSheet
寬度:豎屏?xí)r的寬度(768)
高度:當(dāng)前屏幕的高度(填充整個高度)
UIModalPresentationFormSheet :占據(jù)屏幕中間的一小塊
UIModalPresentationCurrentContext :跟隨父控制器的呈現(xiàn)樣式
過渡樣式 : Modal出來的控制器,是以怎樣的動畫呈現(xiàn)出來
Modal一共4種過渡樣式
UIModalTransitionStyleCoverVertical 從底部往上鉆(默認(rèn))
UIModalTransitionStyleFlipHorizontal 三維翻轉(zhuǎn)
UIModalTransitionStyleCrossDissolve 淡入淡出
UIModalTransitionStylePartialCurl 翻頁(只顯示部分,使用前提呈現(xiàn)樣式必須是UIModalPresentationFullScreen)
3.UIPopoverController
iPad開發(fā)中常見的一種控制器(在iPhone上不允許使用)
跟其他控制器不一樣的是,它直接繼承自NSObject,并非繼承自UIViewController
它只占用部分屏幕空間來呈現(xiàn)信息,而且顯示在屏幕的最前面
要想顯示一個UIPopoverController,需要經(jīng)過下列步驟:
1>設(shè)置內(nèi)容控制器
由于UIPopoverController直接繼承自NSObject,不具備可視化的能力
因此UIPopoverController上面的內(nèi)容必須由另外一個繼承自UIViewController的控制器來提供,
這個控制器稱為“內(nèi)容控制器”
2>設(shè)置內(nèi)容的尺寸:顯示出來占據(jù)多少屏幕空間
3>設(shè)置顯示的位置:從哪個地方冒出來
設(shè)置內(nèi)容控制器有3種方法
在初始化UIPopoverController的時候傳入一個內(nèi)容控制器
- (id)initWithContentViewController:(UIViewController *)viewController;
@property (nonatomic, retain) UIViewController *contentViewController;
- (void)setContentViewController:(UIViewController *)viewController
animated:(BOOL)animated;
設(shè)置內(nèi)容的尺寸有2種方法
@property (nonatomic) CGSize popoverContentSize;
- (void)setPopoverContentSize:(CGSize)size animated:(BOOL)animated;
設(shè)置顯示的位置有2種方法
圍繞著一個UIBarButtonItem顯示(箭頭指定那個UIBarButtonItem)
- (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item
permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections
animated:(BOOL)animated;
item 圍繞著哪個UIBarButtonItem顯示
arrowDirections 箭頭的方向
animated 是否通過動畫顯示出來
圍繞著某一塊特定區(qū)域顯示(箭頭指定那塊特定區(qū)域)
- (void)presentPopoverFromRect:(CGRect)rect
inView:(UIView *)view
permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections
animated:(BOOL)animated;
rect 指定箭頭所指區(qū)域的矩形框范圍(位置和尺寸)
view 參數(shù)rect是以view的左上角為坐標(biāo)原點(0,0)

設(shè)置顯示的位置
如果想讓箭頭指向某一個UIView的做法有2種做法,比如指向一個button
方法1
[popover presentPopoverFromRect:button.bounds
inView:button
permittedArrowDirections:UIPopoverArrowDirectionDown
animated:YES];
方法2
[popover presentPopoverFromRect:button.frame
inView:button.superview
permittedArrowDirections:UIPopoverArrowDirectionDown
animated:YES];
代理對象
@property (nonatomic, assign) id <UIPopoverControllerDelegate> delegate;
是否可見
@property (nonatomic, readonly, getter=isPopoverVisible) BOOL popoverVisible;
箭頭方向
@property (nonatomic, readonly) UIPopoverArrowDirection popoverArrowDirection;
關(guān)閉popover(讓popover消失)
- (void)dismissPopoverAnimated:(BOOL)animated;
防止點擊UIPopoverController區(qū)域外消失
默認(rèn)情況下
只要UIPopoverController顯示在屏幕上,UIPopoverController背后的
所有控件默認(rèn)是不能跟用戶進行正常交互的
點擊UIPopoverController區(qū)域外的控件,UIPopoverController默認(rèn)會消失
要想點擊UIPopoverController區(qū)域外的控件時
不讓UIPopoverController消失,解決辦法是設(shè)置passthroughViews屬性
@property (nonatomic, copy) NSArray *passthroughViews;
這個屬性是設(shè)置當(dāng)UIPopoverController顯示出來時
哪些控件可以繼續(xù)跟用戶進行正常交互。這樣的話,
點擊區(qū)域外的控件就不會讓UIPopoverController消失了
常見報錯
在popover的使用過程中,經(jīng)常會遇到這個錯誤
-[UIPopoverController dealloc] reached while popover is still visible.
錯誤的大體意思是:popover在仍舊可見的時候被銷毀了(調(diào)用了dealloc)
從錯誤可以得出的結(jié)論
當(dāng)popover仍舊可見的時候,不準(zhǔn)銷毀popover對象
在銷毀popover對象之前,一定先讓popover消失(不可見)
通過內(nèi)容控制器設(shè)置內(nèi)容尺寸
以下屬性都是UIViewController的
內(nèi)容控制器可以自行設(shè)置自己在popover中顯示的尺寸
在iOS 7之前
@property (nonatomic,readwrite) CGSize contentSizeForViewInPopover;
從iOS 7開始
@property (nonatomic) CGSize preferredContentSize;
UIPopoverController這個類是只能用在iPad中的
要想在iPhone中實現(xiàn)popover效果,必須得自定義view,可以參考
http://code4app.com/ios/Popover-View-in-iPhone/4fa931bd06f6e78d0f000000