tags:

views:

25

answers:

2

hi i am new to iphone. what i did is displaying 10 images as grid and 3 images in portroide mode, and what i did is when ever i rotate the simulator to landscape then i have to display 4 images.It is also displayed using the code

if(self.interfaceorientation == UIIntefaceorientationPortrait) {
[self abc];
else {
[self abclandscape];
}

here abc and abclandscape are two functions it works fine but, it works from initial means form starting if i rotate to landscape mode or portrait mode it works fine .while in the middle if i rotate from landscape to portrait it does 't goes to [self abc] function. how can i solve this thank u.

A: 

Hi,

What you could do is either use the UIViewController delegates, or use the NSNoticationCenter.
I.E. add in your "viewDidLoad":

        [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:)
                                                     name:UIDeviceOrientationDidChangeNotification object:nil];

And add the funtion:

- (void)orientationChanged:(NSNotification *)notification
{   
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
    if (UIDeviceOrientationIsLandscape(deviceOrientation))
    {
    // Do one thing
    }
    else 
    {
    // Do something else
    }
}

Cheers,
Paul

Paul Peelen
+1  A: 

@mahesh In shouldAutoRototate Method

      use

     if(self.interfaceorientation == UIIntefaceorientationPortrait||self.interfaceorientation == UIIntefaceorientationPortraitUp..)

{ } else { }

arunkumar.p