Search code examples
iphoneiosobjective-cimageuiimageview

Image Bouncing while doing interface orientation


I am having paging in my application. Each page having Image. during the orientation i am changing the frame according to the landscape and portrait orientation. but image is bouncing. It should not bounce and want to set smoothly.

please let us know what can i do.

I am changing the frame in

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

Here are some code.

 - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
    {
        if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
        {
            [self performSelector:@selector(setLandscapeOrientationFrame) withObject:nil afterDelay:(duration/2)];
        }
        else
        {
            [self performSelector:@selector(setPortraitOrientationFrame) withObject:nil afterDelay:(duration/2)];
        }

    }

And in "setPortraitOrientationFrame" and "setLandscapeOrientationFrame" I am changing frame.


Solution

  • If you are working iOS6, you can use autolayout. The reason may be because you have used delay. If you use the code that follows, it may work.

    - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
     {
    
         if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
         {
             [self setLandscapeOrientationFrame];
         }
         else
         {
             [self setPortraitOrientationFrame];
         }
    
    }