我UITableViewCell
在通用应用程序中有一个自定义,我必须为 iPhone 和 iPad 设置不同的框架,我必须考虑不同的方向,但无法识别设备的方向。UIDeviceOrientation
是在错误的地方?UIDeviceOrientation
返回0
。这是中的代码CustomCell.m
-(void) layoutCellPortrait{
if(UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPhone){
//......frame subviews iPhone
}else{
//........frame subviews Ipad
}
}
-(void) layoutCellLandscape{
if(UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPhone){
//.....frame subviews iPhone
}else{
//.......frame subviews Ipad
}
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice]orientation];
NSLog(@"The orientation is è %d", deviceOrientation);//here return 0
if(deviceOrientation == UIInterfaceOrientationPortrait || deviceOrientation== UIInterfaceOrientationPortraitUpsideDown) {
[self layoutCellPortrait];
}
else if (deviceOrientation== UIInterfaceOrientationLandscapeRight){
[self layoutCellLandscape];
}
else if (deviceOrientation==UIInterfaceOrientationLandscapeLeft){
[self layoutCellLandscape];
}
[self.contentView addSubview:self.subviews];
}
return self;
}