どういうことかと言うと、普通にnavigationBarとtoolBarをUIBarStyleBlackTranslucentに設定して、
UIScrollViewをself.viewに突っ込むだけだと、
スクロール範囲がnavigationBarとtoolBarに被ってしまって見栄えが非常に良くない
(例えば一番下までスクロールしても、UIScrollViewのcontentがtoolBarに被ってしまう)
これが例えば、UITableViewContollerを使ったりすると、
tableViewは透けるのにスクロール範囲はnavigationBar, toolBarに被らないように
よろしくやってくれたりする
それをUIScrollViewでやりたい
上記を実現する為に、
- UIScrollViewのcontentの余白をbarのheight分縮める
- UIScrollViewのスクロールバーの余白?もbarのheight分縮める
// 対象のscrollView
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
:
- (void)viewDidLoad
{
[super viewDidLoad];
// barを透明に
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
self.navigationController.toolbar.barStyle = UIBarStyleBlackTranslucent;
UIEdgeInsets insets;
// contentを縮める
insets= self.scrollView.contentInset;
insets.top = self.navigationController.navigationBar.frame.size.height;
insets.bottom = self.navigationController.toolbar.frame.size.height;
self.scrollView.contentInset = insets;
// スクロールバーの範囲を縮める
insets = self.scrollView.scrollIndicatorInsets;
insets.top = self.navigationController.navigationBar.frame.size.height;
insets.bottom = self.navigationController.toolbar.frame.size.height;
self.scrollView.scrollIndicatorInsets = insets;
// そのままだと初期位置がnavigationBarに被るので下にずらす
CGPoint point = self.scrollView.contentOffset;
point.y = -1*self.scrollView.contentInset.top;
self.scrollView.contentOffset = point;
}
これでいろいろ透けさせることができそう(意味深)
参考
No comments:
Post a Comment