[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[notificationCenter addObserver:self selector:@selector(deviceOrientationDidChange) name:UIDeviceOrientationDidChangeNotification object:nil];
orientation = AVCaptureVideoOrientationPortrait;
I want to know beginGeneratingDeviceOrientationNotifications means what and how to work?
3 Réponses :
Lorsque vous écrivez cette ligne: vous dites au périphérique: "Veuillez notifier l'application à chaque fois que l'orientation est modifiée" p> en écrivant ceci: vous dites à l'application: "Veuillez appeler périodientationDidChange code> chaque fois que vous êtes averti que l'orientation est modifiée". P> Maintenant dans le DeviceOrientationDidChange Code> Vous pouvez effectuer les éléments suivants: P> UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationPortrait)
[self doSomething];
else
[self doSomethingElse];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; This is optional to get notifications. Please, share if anybody knows how it works.
SWIFT 3.0 strong> P> Je souhaite que quelqu'un vient de l'écrire à Swift. Je sais que c'est un poste Obj-C, mais je n'ai trouvé aucun message rapide comme celui-ci, alors vous allez ici: P> class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
UIDevice.current.beginGeneratingDeviceOrientationNotifications()
NotificationCenter.default.addObserver(self, selector: #selector(deviceOrientationDidChange), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
}
deinit {
NotificationCenter.default.removeObserver(self)
}
func deviceOrientationDidChange() {
print(UIDevice.current.orientation.rawValue)
}
}