UIScrollView 中的奇怪 UIImageView
非常奇怪的行为,使用此代码的屏幕中心有一个圆点,并且笔尖中没有任何内容的 UIScrollview 。我希望 UIScrollview 应该为空。当我滚动屏幕时,该点会模糊并消失。
- (void)viewDidLoad {
[super viewDidLoad];
NSArray *subviews = [closetScroll subviews];
UIImageView *strange=[subviews objectAtIndex:0];
strange.center = CGPointMake([[UIScreen mainScreen] bounds].size.width/2, [[UIScreen mainScreen] bounds].size.height/2);
strange.alpha=1;
NSLog(@"%@",subviews);
}
控制台输出是:
<UIImageView: 0x4b1f780; frame = (380.5 508.5; 7 7); opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0x4b1f820>
有谁知道为什么?
Very strange behavior, there is a round dot in the center of the screen using this code, and a UIScrollview with nothing inside in a nib. I expect that UIScrollview should be empty. The dot blurs and disappears when I scroll the screen.
- (void)viewDidLoad {
[super viewDidLoad];
NSArray *subviews = [closetScroll subviews];
UIImageView *strange=[subviews objectAtIndex:0];
strange.center = CGPointMake([[UIScreen mainScreen] bounds].size.width/2, [[UIScreen mainScreen] bounds].size.height/2);
strange.alpha=1;
NSLog(@"%@",subviews);
}
The console output is:
<UIImageView: 0x4b1f780; frame = (380.5 508.5; 7 7); opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0x4b1f820>
Does anyone know why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在放大 UIImageView 并调整配置后,我得出结论,UIImageView 实际上是滚动条,如果启用了水平和垂直滚动,则“空”UIScrollview 内部有两个子视图。
After magnifying the UIImageView and tweaking with configurations, I have come to conclude that the UIImageView is actually the scroll bar, and if horizontal and vertical scroll is enabled, an "empty" UIScrollview has two subviews inside.
我有同样的问题。由于这个“特性”,计算子视图的数量可能非常具有欺骗性。
启动应用程序并计算子视图的数量,这将是 1。现在,在模拟器中使用鼠标或在设备上使用手指并从右向左滑动。计算子视图的数量。数字将为 2。
我只能推断出这个额外的 UIImageView 是由 Cocoa Touch 生成的,以便在“弹跳”超出 UIScrollView 边界的末尾时以正确的颜色渲染背景。
I had the same issue. Calculating the number of subviews can be very deceptive, because of this "feature".
Start the application and count the number of subviews, this will be 1. Now, use you mouse in the simulator or finger on the device and swipe from the right to the left. Count the number of subviews. The number will be 2.
I can deduce nothing else than that this extra UIImageView is produced by Cocoa Touch to render the background in the right color when "bouncing" beyond the end of the UIScrollView's bounds.