Strange UIImageView in UIScrollView

人盡茶涼 提交于 2020-01-01 07:57:53

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/5388703/strange-uiimageview-in-uiscrollview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!