Đây là một bước để đạt được điều này:
+ (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;
}];
}
Lưu ý: Giữ thiết bị của bạn bằng phẳng trên bàn hoặc các bản cập nhật gia tốc sẽ quay khung cảnh trở lại.
Nguồn
2012-08-14 08:25:10
Điều này dường như không hoạt động trong trình mô phỏng. Tôi không có thiết bị vì vậy tôi đã không thử nghiệm nó trên nó, nhưng thử nghiệm KIF sẽ chạy trên mô phỏng thông qua VaxSim vì vậy nó đã chạy trên giả lập. Bạn có thể vui lòng xác nhận rằng điều này có/không chạy trên trình mô phỏng không? Tôi đang sử dụng trình mô phỏng iOS 6.1. – applefreak
Tệ của tôi! Nó chỉ hoạt động nếu Ứng dụng hỗ trợ định hướng được đề cập! – applefreak