2016-06-23 3 views

ответ

2

Основываясь на некоторой логике, найденной в hereKIF testing framework, я полагаю, это должно быть возможно.

код Objective-C за ссылку выглядит следующим образом:

- (void)simulateDeviceRotationToOrientation:(UIDeviceOrientation)orientation 
{ 
    [[UIDevice currentDevice] setValue:[NSNumber numberWithInt:orientation] forKey:@"orientation"]; 
} 

Свифт эквивалент этого кода будет выглядеть следующим образом:

func simulateDeviceRotation(toOrientation orientation: UIDeviceOrientation) { 
    let orientationValue = NSNumber(integer: orientation.rawValue) 
    UIDevice.currentDevice().setValue(orientationValue, forKey: "orientation") 
} 

И тогда мы просто называем это что-то например:

simulateDeviceRotation(toOrientation: .LandscapeLeft) 

Возможно, нам нужна функция, которая запускает некоторый код для каждой ориентации?

func forEachOrientation(block:() -> Void) { 
    for orientation in [UIDeviceOrientation.Portrait, UIDeviceOrientation.LandscapeLeft, UIDeviceOrientation.PortraitUpsideDown, UIDeviceOrientation.LandscapeRight] { 
     simulateDeviceRotation(toOrientation: orientation) 
     block() 
    } 
} 

И мы можем назвать его просто так:

forEachOrientation { 
    // do a thing 
} 

Из моего опыта, это на самом деле, кажется, не работает на IOS 9 тренажеров, но он работает на IOS 8 тренажерах. Я не знаю, будет ли это работать на реальных устройствах.

 Смежные вопросы

  • Нет связанных вопросов^_^