-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
imageView.image = [UIImage imageNamed:@"Sample.png"];
[self.view addSubview:imageView];
NSArray *subviews = [self.view subviews];
for(id element in subviews) {
if ([[element class] isKindOfClass:[UIImageView class]]) //check if the object is a UIImageView
{
NSLog(@"element is a UIImageView\n");
[element setCenter:CGPointMake(500., 500.)];
} else {
NSLog(@"element is NOT a UIImageView\n");
}
}
}
我预计输出是“元素是 UIImageView,但它实际上元素不是 UIImageView。为什么?不是有其他子视图。只有一个。此外,运行时,图像显示在 100,100,而不是 500,500正如预期的那样。