2010-04-27 116 views
1

我已经子类UITableViewCell并通过layoutSubviews方法合并了一些子视图。所有视图分配,并在initWithStyle方法启动,帧在layoutSubviews方法设置,像这样:自动调整子类UITableViewCell子视图

initWithStyle:... { 
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectZero]; 
myLabel.someProperties = Configured; 
[self.contentView addSubview:myLabel]; 

layoutSubviews { 
CGRect labelRect = CGRectMake(10.0f, 5.0f, 35.0f, 180.0f); 
myLabel.frame = labelRect; 

设置在的viewController的shouldAutoRotateOrientation为YES旋转NavigationController,的tableView和UIToolbar适当的,但内容tableViewCells不会移动。至于AutoResizingMasks,我不清楚要添加到哪里或要添加什么内容。到目前为止我尝试过的组合都没有做任何事情。有人能帮我一把吗?

谢谢!

+0

不当您旋转设备时调用layoutSubviews? – Skie 2010-04-27 16:49:28

+0

我不确定。我必须尝试NSLog并看看。 – Justin 2010-04-27 17:48:46

回答

1

我想出答案就是使用条件编码放置视角画面,依赖于方位,在layoutSubviews方法

-(void)layoutSubviews { 
    //For portrait mode (NOT PORTRAIT UPSIDE DOWN) 
    if (UIDeviceOrientationIsPortrait([[UIDevice currentDevice]orientation])) { 
     CGRect portraitFrame = CGRectMake(Portrait Frame Coordinates); 
     myLabel.frame = portraitFrame; 
    } else { 
    //For landscape modes 
     CGRect landscapeFrame = CGRectMake(landscape frame coordinates); 
     myLabel.frame = landscapeFrame; 
    } 
} 

好像砍死在一起,但它的子类UITableViewCells工作

相关问题