当我的视图加载以识别我的iDevice的方向时,我遇到了调用void的问题。它只在我的视图旋转时被调用然后它被调用,但我希望它从我的程序的最开始被调用。这就是我所拥有的:
- (void)viewDidLoad {
[super viewDidLoad];
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
platform = [NSString stringWithCString:machine encoding:NSUTF8StringEncoding];
free(machine);
UIApplication *app = [UIApplication sharedApplication];
UIInterfaceOrientation currentOrientation = app.statusBarOrientation;
[self doLayoutForOrientation:currentOrientation];
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration {
[self doLayoutForOrientation:toInterfaceOrientation];
}
- (void)doLayoutForOrientation:(UIInterfaceOrientation)orientation {
if (UIInterfaceOrientationIsPortrait(orientation)) {
[self layoutPortrait];
} else {
[self layoutLandscape];
}
}
- (void)layoutPortrait {
if ([platform isEqualToString:@"iPhone1,2"] || [platform isEqualToString:@"iPhone2,1"] || [platform isEqualToString:@"iPhone3,1"] || [platform isEqualToString:@"iPhone3,3"] || [platform isEqualToString:@"iPhone4,1"] || [platform isEqualToString:@"iPod1,1"] || [platform isEqualToString:@"iPod2,1"] || [platform isEqualToString:@"iPod3,1"] || [platform isEqualToString:@"iPod4,1"] || [platform isEqualToString:@"iPhone5,1"] || [platform isEqualToString:@"iPhone5,2"] || [platform isEqualToString:@"iPhone5,3"] || [platform isEqualToString:@"iPhone5,4"] || [platform isEqualToString:@"iPhone6,1"] || [platform isEqualToString:@"iPhone6,2"] || [platform isEqualToString:@"iPod5,1"]) {
self.autonomousOnPlayingField.frame = CGRectMake(218, 40, 94, 28);
self.redAutonomousOnPlayingField.frame = CGRectMake(218, 40, 94, 28);
self.autonomousReleasedKickstand.frame = CGRectMake(218, 77, 94, 28);
self.redAutonomousReleasedKickstand.frame = CGRectMake(218, 77, 94, 28);
self.autonomousParkingZoneStepper.frame = CGRectMake(218, 37, 94, 29);
self.redAutonomousParkingZoneStepper.frame = CGRectMake(218, 37, 94, 29);
self.autonomousWithAutonomousBallStepper.frame = CGRectMake(218, 74, 94, 29);
self.redAutonomousWithAutonomousBallStepper.frame = CGRectMake(218, 74, 94, 29);
self.autonomousCenterGoal.frame = CGRectMake(218, 33, 94, 28);
self.redAutonomousCenterGoal.frame = CGRectMake(218, 33, 94, 28);
} else if ([platform isEqualToString:@"iPhone7,2"]) {
} else if ([platform isEqualToString:@"iPhone7,1"]) {
} else if ([platform isEqualToString:@"iPad1,1"] || [platform isEqualToString:@"iPad2,1"] || [platform isEqualToString:@"iPad2,2"] || [platform isEqualToString:@"iPad2,3"] || [platform isEqualToString:@"iPad2,4"] || [platform isEqualToString:@"iPad2,5"] || [platform isEqualToString:@"iPad2,6"] || [platform isEqualToString:@"iPad2,7"] || [platform isEqualToString:@"iPad3,1"] || [platform isEqualToString:@"iPad3,2"] || [platform isEqualToString:@"iPad3,3"] || [platform isEqualToString:@"iPad3,4"] || [platform isEqualToString:@"iPad3,5"] || [platform isEqualToString:@"iPad3,6"] || [platform isEqualToString:@"iPad4,1"] || [platform isEqualToString:@"iPad4,2"] || [platform isEqualToString:@"iPad4,3"] || [platform isEqualToString:@"iPad4,4"] || [platform isEqualToString:@"iPad4,5"] || [platform isEqualToString:@"iPad4,6"] || [platform isEqualToString:@"iPad4,7"] || [platform isEqualToString:@"iPad4,8"] || [platform isEqualToString:@"iPad4,9"] || [platform isEqualToString:@"iPad5,3"] || [platform isEqualToString:@"iPad5,4"] || [platform isEqualToString:@"i386"] || [platform isEqualToString:@"x86_64"]) {
}
}
- (void)layoutLandscape {
if ([platform isEqualToString:@"iPhone1,2"] || [platform isEqualToString:@"iPhone2,1"] || [platform isEqualToString:@"iPhone3,1"] || [platform isEqualToString:@"iPhone3,3"] || [platform isEqualToString:@"iPhone4,1"] || [platform isEqualToString:@"iPod1,1"] || [platform isEqualToString:@"iPod2,1"] || [platform isEqualToString:@"iPod3,1"] || [platform isEqualToString:@"iPod4,1"] || [platform isEqualToString:@"iPhone5,1"] || [platform isEqualToString:@"iPhone5,2"] || [platform isEqualToString:@"iPhone5,3"] || [platform isEqualToString:@"iPhone5,4"] || [platform isEqualToString:@"iPhone6,1"] || [platform isEqualToString:@"iPhone6,2"] || [platform isEqualToString:@"iPod5,1"]) {
self.autonomousOnPlayingField.frame = CGRectMake(213, 40, 347, 28);
self.redAutonomousOnPlayingField.frame = CGRectMake(213, 40, 347, 28);
self.autonomousReleasedKickstand.frame = CGRectMake(213, 77, 347, 28);
self.redAutonomousReleasedKickstand.frame = CGRectMake(213, 77, 347, 28);
self.autonomousParkingZoneStepper.frame = CGRectMake(466, 37, 94, 29);
self.redAutonomousParkingZoneStepper.frame = CGRectMake(466, 37, 94, 29);
self.autonomousWithAutonomousBallStepper.frame = CGRectMake(466, 74, 94, 29);
self.redAutonomousWithAutonomousBallStepper.frame = CGRectMake(466, 74, 94, 29);
self.autonomousCenterGoal.frame = CGRectMake(213, 33, 347, 28);
self.redAutonomousCenterGoal.frame = CGRectMake(213, 33, 347, 28);
} else if ([platform isEqualToString:@"iPhone7,2"]) {
} else if ([platform isEqualToString:@"iPhone7,1"]) {
} else if ([platform isEqualToString:@"iPad1,1"] || [platform isEqualToString:@"iPad2,1"] || [platform isEqualToString:@"iPad2,2"] || [platform isEqualToString:@"iPad2,3"] || [platform isEqualToString:@"iPad2,4"] || [platform isEqualToString:@"iPad2,5"] || [platform isEqualToString:@"iPad2,6"] || [platform isEqualToString:@"iPad2,7"] || [platform isEqualToString:@"iPad3,1"] || [platform isEqualToString:@"iPad3,2"] || [platform isEqualToString:@"iPad3,3"] || [platform isEqualToString:@"iPad3,4"] || [platform isEqualToString:@"iPad3,5"] || [platform isEqualToString:@"iPad3,6"] || [platform isEqualToString:@"iPad4,1"] || [platform isEqualToString:@"iPad4,2"] || [platform isEqualToString:@"iPad4,3"] || [platform isEqualToString:@"iPad4,4"] || [platform isEqualToString:@"iPad4,5"] || [platform isEqualToString:@"iPad4,6"] || [platform isEqualToString:@"iPad4,7"] || [platform isEqualToString:@"iPad4,8"] || [platform isEqualToString:@"iPad4,9"] || [platform isEqualToString:@"iPad5,3"] || [platform isEqualToString:@"iPad5,4"] || [platform isEqualToString:@"i386"] || [platform isEqualToString:@"x86_64"]) {
}
}
我可以做什么,以便从我的(void)doLayoutForOrientation:(UIInterfaceOrientation)orientation
致电(void)viewDidLoad
?