-(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(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,而不是500,500如预期.