iOS UITableviewWrapperView 和 automaticallyAdjustsScrollViewInsets屬性


  關於在navigationController下面使用tableView在豎直方向會遇到frame的y值的困惑,
會遇到視圖控制器的這個屬性: automaticallyAdjustsScrollViewInsets.
  apple的解釋:
 

A Boolean value that indicates whether the view controller should automatically adjust its scroll view insets.

 

The default value of this property is YES, which allows the view controller to adjust its scroll view insets in response to the screen areas consumed by the status bar, navigation bar, and toolbar or tab bar. Set to NO if you want to manage scroll view inset adjustments yourself, such as when there is more than one scroll view in the view hierarchy.

 

  這是指示ViewController是否自動調整subview中的scrollView位置的布爾變量。
  此屬性的默認值是YES,它使得視圖控制器來調節響應的狀態欄,導航欄占用的屏幕區域的scrollview,和toolbar或tabBar。,如果你要自己管理插入調整scrollView就設置為NO。

 在iOS7以下系統,UITableViewCell.superview就是UITableView,但在IOS7中,cell上面還多了一個UITableViewWrapperView,所以需要UITableViewCell.superview.superview獲取UITableView
 
iOS 獲取操作系統的版本

 1 [[[UIDevice currentDevice] systemVersion] floatValue] 

 
 1 UITableView *tableView;
 2 
 3      float Version=[[[UIDevice currentDevice] systemVersion] floatValue];
 4 
 5     if(Version>=7.0)
 6 
 7     {
 8 
 9        tableView = (UITableView *)self.superview.superview;
10 
11     }
12 
13     else
14 
15     {
16 
17         tableView=(UITableView *)self.superview;
18 
19     }
20 
21      NSIndexPath *indexPath= [tableView indexPathForCell:self];
22 
23     indexPath = [NSIndexPath indexPathForRow:kImage1IndexinSection:indexPath.row];
24 
25  

 

但是今天所做的項目里用到了tabbarController中一個VC的childVC中使用tableView時候,在切換tabbar的VC時,ChildVC的table會掉64(navigationBar的高度),設置automaticallyAdjustsScrollViewInsets 也無效,

所以只好拿到UITableviewWrapperView強行設置frame:

1 for (UIView *subview in tableView.subviews)
2 {
3     if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewWrapperView"])
4     {
5         subview.frame = CGRectMake(0, 0, tableView.bounds.size.width, tableView.bounds.size.height);
6     }
7 }

應該是automaticallyAdjustsScrollViewInsets的問題,以后研究

 

參考鏈接: http://stackoverflow.com/questions/27671324/uitableviewwrapperview-and-uitableview-size-differs-with-autolayout

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM