【发布时间】:2010-05-19 01:51:23
【问题描述】:
我创建了一个 UIView 作为子视图,并在该子视图中添加了一个 UIImageView 作为子视图。
UIView *viewCreated;
UIButton *buttonCreated;
UIImageView *imageViewCreated;
CGRect myFrame = CGRectMake(0, 0, 1024, 1024);
viewCreated = [[UIView alloc] initWithFrame:myFrame];
[viewCreated setTag:intTag];
viewCreated.backgroundColor = [UIColor redColor];
[self.view addSubview:viewCreated];
[self randomize];
UIImage *d1Image = [UIImage imageNamed:[NSString stringWithFormat:@"image%d.png", randomNumber]];
imageViewCreated = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f,0.0f,1024.0f, 1024.0f)];
[imageViewCreated setImage:[UIImage imageNamed:[NSString stringWithFormat:@"image%d.png", randomNumber]]];
[viewCreated addSubview:imageViewCreated];
//[imageViewCreated release];
return [viewCreated autorelease];
但是当这段代码执行时,只有第一个子视图被动画和调整大小。 UiimageView 向左移动 200 像素,但没有调整大小。
NSLog(@"sender tag %i",[sender tag]);
UIView *currentView = [self.view viewWithTag:[sender tag]];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.5];
currentView.frame = CGRectMake(-200, 0,40, 102);
[UIView commitAnimations];
我很确定我没有以编程方式正确创建子视图,因为当我在 Interface Builder 中执行此操作时,它会按预期工作。
我是否必须做一些特定的事情才能将第二个子视图的行为实际附加到第一个子视图?
【问题讨论】:
-
我可能错过了一些东西,但 1024 x 1024 在 iPhone 上似乎是一个非常大的 UIView。
-
你是对的。我贴错标签了。应该是 iPad。感谢您指出这一点。
标签: objective-c xcode ipad interface-builder