iOS 懸停 你值得一看

導(dǎo)航條隱藏
顯示導(dǎo)航條

話不多說,我們直接上代碼吧:

添加兩個(gè)屬性
//UIScrollView
@property (nonatomic, strong) UIScrollView *scView;
//懸停View
@property (nonatomic, strong) UIView *topView;
//不要忘記添加 UIScrollView的協(xié)議


//存在導(dǎo)航條時(shí) 將導(dǎo)航條隱藏
self.navigationController.navigationBar.hidden = YES;
//存在導(dǎo)航條時(shí)
_scView = [[UIScrollView alloc]initWithFrame:[UIScreen mainScreen].bounds];
//不存在導(dǎo)航條時(shí)
//? ? _scView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height-64)];
[self.view addSubview:_scView];
_scView.backgroundColor = [UIColor redColor];
_scView.contentSize = CGSizeMake(self.view.frame.size.width, 1000);
//創(chuàng)建一個(gè)button
UIButton *but = [[UIButton alloc]initWithFrame:CGRectMake(100, 300, 100, 100)];
[_scView addSubview:but];
but.backgroundColor = [UIColor greenColor];
//創(chuàng)建頂部的條
_topView = [[UIView alloc]initWithFrame:CGRectMake(0, 200, self.view.frame.size.width, 50)];
_topView.backgroundColor = [UIColor greenColor];
[_scView addSubview:_topView];
self.scView.delegate = self;


- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (self.scView.contentOffset.y > 200) {
//不存在導(dǎo)航條時(shí)
//self.topView.frame = CGRectMake(0, 64, self.view.frame.size.width, 50) ;
//存在導(dǎo)航條時(shí)
self.topView.frame = CGRectMake(0, 0, self.view.frame.size.width, 50) ;
//添加的視圖 不同
[self.view addSubview:self.topView];
}else
{self.topView.frame = CGRectMake(0, 200, self.view.frame.size.width, 50) ;
[self.scView addSubview:self.topView];
}




根據(jù)偏移量的多少 來判斷View的移動
+重點(diǎn)+懸停后所填加的視圖為主視圖

+++++中心? 順手點(diǎn)個(gè)贊

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • *7月8日上午 N:Block :跟一個(gè)函數(shù)塊差不多,會對里面所有的內(nèi)容的引用計(jì)數(shù)+1,想要解決就用__block...
    炙冰閱讀 2,726評論 1 14
  • 關(guān)愛老人不光是要他們吃好,穿好,要有一定的物質(zhì)生活以外,更要有好的交流,溝通,這是濰坊惟愛公益助殘服務(wù)中心的公益人...
    隨心姐閱讀 607評論 3 2
  • 其實(shí)我也寫作也堅(jiān)持了有幾年,我一直有寫博客的習(xí)慣,但我有一夢想就像當(dāng)一個(gè)作家,但每次和父母說你“”不要做白日夢了。...
    cca8645a5515閱讀 517評論 0 0

友情鏈接更多精彩內(nèi)容