国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

iphone/ipad關(guān)于size,frameandbounds總結(jié)和UIScrollview學(xué)習(xí)筆記

2019-11-14 19:52:42
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

1. iphone/ipad大小

 

DeviceScreen dimensions(in points)
iphone and ipod320 X 480
ipad768 X 1024

 

2. UIScreen bounds and applicationFrame

[UISCreen mainScreen].bounds, 永遠(yuǎn)返回portait模式的width/height, 也就是說(shuō)width:320 height:480 for iPhone

[UISCreen mainScreen].applicationFrame更加復(fù)雜一些,它考慮了status bar的高度。

portait模式, x:0, y:20, width:320, height:460

landscape,   x:20, y:0, width:300, height:480

關(guān)于frame和bounds的區(qū)別,請(qǐng)參考UIView中的frame和bounds屬性的區(qū)別

3. status bar height: 20, tool bar height: 44, tab bar height:44

4. UIScrollView

 

  • contentSize和contentInSet

 

 

  • contentOffSet:
當(dāng)前scroll view可見(jiàn)的左上角頂點(diǎn)在content view中的位置, 可以在代碼中通過(guò)控制這個(gè)直實(shí)現(xiàn)滾動(dòng)scroll view. 例如如果一個(gè)view里面有很多text field,當(dāng)鍵盤(pán)顯示的時(shí)候,這個(gè)text field可能會(huì)被隱藏掉,因此我們需要把text field scroll到可見(jiàn)的區(qū)域。如下圖所示的情況:
 
// Called when the UIKeyboardDidShowNotification is sent.- (void)keyboardWasShown:(NSNotification*)aNotification{    NSDictionary* info = [aNotification userInfo];    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;     UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);    scrollView.contentInset = contentInsets;    scrollView.scrollIndicatorInsets = contentInsets;     // If active text field is hidden by keyboard, scroll it so it's visible    // Your application might not need or want this behavior.    CGRect aRect = self.view.frame;    aRect.size.height -= kbSize.height;    if (!CGRectContainsPoint(aRect, activeField.frame.origin) ) { //判斷該text field是否在可見(jiàn)區(qū)域        CGPoint scrollPoint = CGPointMake(0.0, instance); //這里需要計(jì)算需要scroll的長(zhǎng)度,假設(shè)instance是計(jì)算出來(lái)的結(jié)果。        [scrollView setContentOffset:scrollPoint animated:YES];    }}

  

  • UIScroll view使用翻頁(yè)模式

 

原文來(lái)自這里, 這里介紹幾個(gè)關(guān)鍵的內(nèi)容:

1.  pagingMode需要設(shè)置為YES

2. contentSize是所有頁(yè)數(shù)的width總和, 例如你需要顯示100頁(yè),那contentSize的寬度就是100*scroll.frame.size.width

3. showsHorizontalScrollIndicator和showsVerticalScrollIndicator設(shè)置為NO

然后需要在scroll view的delegate中實(shí)現(xiàn)scrollViewDidScroll:方法,這個(gè)方法在scroll view的contentOffSet發(fā)生變化的時(shí)候被調(diào)用。翻頁(yè)模式的核心思想就是scroll view需要顯示下一頁(yè)的時(shí)候,創(chuàng)建一個(gè)view, 在這個(gè)view上準(zhǔn)備好數(shù)據(jù),然后把這個(gè)view加到scroll view當(dāng)前顯示的位置。

代碼如下所示,另外還可以改進(jìn)的一個(gè)地方是需要翻頁(yè)之前,需要把后面一頁(yè)的內(nèi)容也顯示出來(lái),否則會(huì)有一半黑的屏幕顯示。 

-(void) loadPageView:(NSUInteger)page{    UIView* view = [[UIView alloc] init];    view.backgroundColor = [UIColor whiteColor];        CGRect rc = self.view.frame;    rc.origin.y = 0;    rc.origin.x = page * self.view.frame.size.width;  //創(chuàng)建一個(gè)view,調(diào)整x直,因?yàn)槠渌焙蛃croll view都是一樣的    view.frame = rc;        UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, rc.size.width, 40)];    label.text = [NSString stringWithFormat:@"current page is :%d", page];    [view addSubview:label];        [(UIScrollView*)self.view addSubview:view];}- (void)scrollViewDidScroll:(UIScrollView *)scrollView{    if (scrollView.contentOffset.x >= (myCurrentPage+0.5) * self.view.frame.size.width) //需要顯示下一頁(yè)了    {        myCurrentPage++;        [self loadPageView:myCurrentPage];    }}

  


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 都匀市| 客服| 英德市| 饶河县| 景谷| 茂名市| 阿鲁科尔沁旗| 大名县| 通州市| 门源| 卢氏县| 屏东县| 麻城市| 水富县| 临猗县| 荔波县| 陇南市| 睢宁县| 永兴县| 广州市| 荆州市| 长沙市| 惠来县| 杂多县| 阿合奇县| 长海县| 镇宁| 班戈县| 河西区| 法库县| 隆德县| 宁武县| 资溪县| 运城市| 吉木乃县| 定南县| 新泰市| 梧州市| 青岛市| 九江县| 云梦县|