iOS7's subview trimmed if out of parent view bounds
来源:互联网 发布:邯郸软件开发公司 编辑:程序博客网 时间:2024/06/05 05:39
iOS7's subview trimmed if out of parent view bounds
bringSubviewToFront problem?
1.
I've rumbled through new UI info from apple - didn't help.
Now let the code and the screenshots show you the problem i've ran into. To ensure that is not my buggy code, i've created a new project, with a single file - a UIViewController that has a tableView inside id. the delegates are set.
I do the following:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ // Return the number of sections. return 3;}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 3;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *CellIdentifier = @"UITableViewCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } cell.textLabel.text = [NSString stringWithFormat:@"%d",indexPath.row]; // Configure the cell... UIView * redView = [[UIView alloc] initWithFrame:CGRectMake(0, -10, 100, 20)]; redView.backgroundColor = [UIColor redColor]; [cell addSubview:redView]; return cell;}
The table view is set on Grouped. Lets run it on iOS 6:
Solution:It's because iOS 7 introduced some changes to the view hierarchy of UITableViewCells.
It used to be UITableViewCell view -> contentView
.
Now it's more like UITableViewCell view -> scrollView -> contentView
.
The solution is to set clipsToBounds = NO
on the scrollView (which is set to YES by default). And the way to achieve that is through the superview
property.
So basically in iOS6 and prior, to allow content to spill out of the cell bounds, you would do:
self.clipsToBounds = NO; //cell's viewself.contentView.clipsToBounds = NO; //contentView
In iOS7 you have to also prevent the scrollview from not clipping so you'd do something like:
self.clipsToBounds = NO; //cell's viewself.contentView.clipsToBounds = NO; //contentViewself.contentView.superview.clipsToBounds = NO; //scrollView
And the backwards compatible solution I use is:
self.clipsToBounds = NO;self.contentView.clipsToBounds = NO;if ([self.contentView.superview isKindOfClass:[NSClassFromString(@"UITableViewCellScrollView") class]]) self.contentView.superview.clipsToBounds = NO;
Keep in mind this is Hacky™ and if the view hierarchy changes again in iOS 8, you might be in trouble. Unfortunately it seems Apple doesn't want us to spill content out of UITableViewCells so AFAIK this is the only workable solution.
2.
The -[UIView bringSubviewToFront:]
method only works for direct children, not grandchildren. Remember that the view hierarchy is a tree, and normally a view only knows about its "parent" (or superview) and its direct "children" (or subviews). You would need to do something like this:
// First, get the view embedding the grandchildview to front.[self bringSubviewToFront:[grandchildview superview]];// Now, inside that container view, get the "grandchildview" to front. [[grandchildview superview] bringSubviewToFront:grandchildview];
- iOS7's subview trimmed if out of parent view bounds
- ArgumentException: Index out of bounds
- To see an outline of a view’s subview hierarchy at runtime
- flexlib dataGrid out of bounds 解决方法
- Range or index out of bounds
- 数组溢出 Array out of bounds
- raised exception "Index out of Bounds"
- Range {2147483648, 4294967295} out of bounds;
- TypeError: value is out of bounds
- ValueError: y_i value out of bounds
- CWE -- Out-of-bounds Write 例子
- (ios7) 解决代码布局View, ios7 中 subView 高度增加StatusBar20dp的问题,保证Ios6,ios7代码一致
- (ios7) 解决代码布局View, ios7 中 subView 高度增加StatusBar20dp的问题,保证Ios6,ios7代码一致
- (ios7) 解决代码布局View, ios7 中 subView 高度增加StatusBar20dp的问题,保证Ios6,ios7代码一致
- (ios7) 解决代码布局View, ios7 中 subView 高度增加StatusBar20dp的问题,保证Ios6,ios7代码一致
- (ios7) 解决代码布局View, ios7 中 subView 高度增加StatusBar20dp的问题,保证Ios6,ios7代码一致
- (ios7) 解决代码布局View, ios7 中 subView 高度增加StatusBar20dp的问题,保证Ios6,ios7代码一致
- The fully qualified name of the bean's class, except if it serves only as a parent definition ...
- vim 复制、删除多行
- 操作符重载C++
- java泛型之二——方法泛型
- WebSphere经典错误解析与总结
- usb 转串口 rs232 协议 pl2303 ,max232作用
- iOS7's subview trimmed if out of parent view bounds
- 无线网卡的查看与配置——iw,iwconfig,ethtool
- CentOS6.3安装gcc_g++
- linux 拷贝文件夹命令
- 浅谈PHP缓存技术
- 去除警告 Android NDK: WARNING:
- 精心挑选的12款优秀 jQuery Ajax 分页插件和教程
- [RDLC]报表根据字段列动态加载图片(二)
- vs2010打包 启动条件的配置