-1

when i incline horizontally an iPad device i obtain a strange behaviour. The notification:

 NSNotificationCenter.defaultCenter().addObserver(self, selector: "MySelector", name: UIDeviceOrientationDidChangeNotification, object: nil)

has been triggered and invoke "MySelector" causing unuseful ui update. There is a way to avoid the triggering of my selector when my device has been horizontally inclined?

Andrea Bozza
  • 1,374
  • 2
  • 12
  • 31

2 Answers2

0

What I see from the following previously asked question: Link -- is that if you do not want such a notification to appear, then you will want to override the viewDidDisappear method and call removeObserver(). I am not sure if this is the answer you are looking for, since I had some trouble understanding your original question. Let me know if this is what you wanted to know.

Community
  • 1
  • 1
Michael Fourre
  • 3,005
  • 3
  • 15
  • 26
  • Doing that will disable orientation flipping all together, I believe the poster is saying if he has a device laying flat on a surface facing horizontal, and he lifts the screen up and it is still horizontal, it is still calling the orientationdidchange notification. – Knight0fDragon Oct 16 '15 at 17:40
  • Hmm, okay, I didn't think about that being what the OP meant by the question. – Michael Fourre Oct 16 '15 at 18:06
0

Try wrapping the call function in an if condition to ensure that the orientation changed. This is pseudo code:

func MySelector
{
  if oldorientation != neworientation
  {
      do stuff
  }
}

If this code is still firing, then that means that the system is going to portrait then horizontal real quick, and you may have to put in a small timer or something to double check the orientation.

Knight0fDragon
  • 16,609
  • 2
  • 23
  • 44