7
votes

MendingeneratingDeviceSorientationNotifications Comment travailler

    [[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?

0 commentaires

3 Réponses :


26
votes

Lorsque vous écrivez cette ligne: xxx pré>

vous dites au périphérique: "Veuillez notifier l'application à chaque fois que l'orientation est modifiée" p>

en écrivant ceci: xxx pré>

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];


0 commentaires

2
votes
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
This is optional to get notifications.
Please, share if anybody knows how it works.

0 commentaires

8
votes

SWIFT 4.2 strong> xxx pré>

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)
    }

}


0 commentaires