Tutaj jest krokiem do osiągnięcia tego celu:
+ (KIFTestStep*) stepToInterfaceOrientation: (UIInterfaceOrientation) toInterfaceOrientation {
NSString* orientation = UIInterfaceOrientationIsLandscape(toInterfaceOrientation) ? @"Landscape" : @"Portrait";
return [KIFTestStep stepWithDescription: [NSString stringWithFormat: @"Rotate to orientation %@", orientation]
executionBlock: ^KIFTestStepResult(KIFTestStep *step, NSError *__autoreleasing *error) {
if([UIApplication sharedApplication].statusBarOrientation != toInterfaceOrientation) {
UIDevice* device = [UIDevice currentDevice];
SEL message = NSSelectorFromString(@"setOrientation:");
if([device respondsToSelector: message]) {
NSMethodSignature* signature = [UIDevice instanceMethodSignatureForSelector: message];
NSInvocation* invocation = [NSInvocation invocationWithMethodSignature: signature];
[invocation setTarget: device];
[invocation setSelector: message];
[invocation setArgument: &toInterfaceOrientation atIndex: 2];
[invocation invoke];
}
}
return KIFTestStepResultSuccess;
}];
}
Uwaga: Przechowywać urządzenie płasko na stole lub aktualizacji akcelerometru będzie obracać widok do tyłu.
To nie działa na symulatorze. Nie mam urządzenia, więc nie testowałem go, ale testy KIF będą działały na symulatorach za pośrednictwem VaxSim, więc musi działać na symulatorze. Czy możesz potwierdzić, że to działa/nie działa na symulatorze? Używam symulatora iOS 6.1. – applefreak
Moja zła! Działa tylko wtedy, gdy aplikacja obsługuje daną orientację! – applefreak