供参考:我想知道为什么需要两次点击按钮来完成这个UIImageView代码?
@interface rjhccViewController : UIViewController{
int myInt;
IBOutlet UIImageView *testcontainer;
IBOutlet UILabel *heightS;
IBOutlet UILabel *widthS;
}
-(IBAction) img1;
-(IBAction) img2;
@end
-(IBAction)img1{
UIImage *img = [UIImage imageNamed:@"p.jpeg"];
[testcontainer setImage:img];
[testcontainer setFrame:CGRectMake(0,0,50,50)];
int myInt = (int) img.size.height;
NSString *imgheight = [NSString stringWithFormat:@"%i",[[NSNumber numberWithFloat:img.size.height] intValue]];
heightS.text = imgheight;
}
所以我有这样的附加到按钮。当我点击按钮时,图像显示出来,高度被报告,但容器不会改变大小。当我再次点击该按钮时,它会转到正确的CGRectMake ...不知道为什么?
罗布
TestContainer是一个'UIImageView'吗? – DrummerB
是的,这是...我已经在Objective-C和Cocoa的土地上2天了,所以相当新的这个 – BostonMacOSX