我在不使用界面生成器的情况下创建了多个图像。我使用了这段代码:
for (Row* row in parser.rows) {
CGRect IphoneFrameImageRect;
IphoneFrameImageRect = CGRectMake(10, 10, 150.0f, 150.0f);
UIImageView *IphoneFrame = [[UIImageView alloc] initWithFrame:IphoneFrameImageRect];
NSString *IphoneFrameurl = [NSString stringWithFormat:@"http://some.url.com/iphone/IphoneFrame.png"];
[IphoneFrame setImage:[UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString:IphoneFrameurl]]]];
[IphoneFrame setTag:(i)];
IphoneFrame.opaque = YES; // explicitly opaque for performance
[self.view addSubview:IphoneFrame];
[IphoneFrame release];
}
我需要在横向模式下将这些图像移动到不同的位置。我确实标记了每个图像,看起来我可以使用此标记选择图像。但是我怎样才能给图像一个新的坐标呢?我有这个代码:
-(void)positionViews {
UIInterfaceOrientation destOrientation = self.interfaceOrientation;
int i=4; //Picture with tag=4 for example
UIImage *tempImage=(UIImage *)[self.view viewWithTag:(i)];
// HOW TO MOVE ??
}
我可以使用以下代码通过按钮执行此操作:
UIButton *tempButton=(UIButton *)[self.view viewWithTag:i];
[temp setFrame:CGRectMake(x, y, X10ButtonWidth, X10ButtonHeight)];