I have the following code in a method. When I run this in the simulator the debugger skips right over the code?? What am I missing?
if (([[UIDevice currentDe
I recommend you to use my highlighted code instead of yours to safe some code of lines.
-(void) viewDidLoad
{
[super viewDidLoad];
[self rotations];
}
-(void)rotations
{
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
}
-(void) orientationChanged:(NSNotification *)notification
{
//USE THIS PART
//USE THIS PART
//USE THIS PART
//USE THIS PART
//USE THIS PART
if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation))
{
}
}
INSTEAD OF
if([[UIDevice currentDevice] orientation] == UIInterfaceOrientationPortrait ||
[[UIDevice currentDevice] orientation] == UIInterfaceOrientationPortraitUpsideDown)
{
}
Another way of doing this without turning on orientation notification would be to
Step 1: Save the current orientation in a local variable myCurrentOrientation
and assign it like this:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration
{
myCurrentOrientation = toInterfaceOrientation;
}
Step 2: Use myCurrentOrientation
for your check
if (UIInterfaceOrientationIsLandscape(myCurrentOrientation) == YES) {
// landscape
}
else {
// portrait.
}