1

I am working on a project where I have added UIWebviews in the UIscrollview to show the description. I did this because I want to add the swipe effect to move to the new description page. Now, I want to resize that UIscrollview and its content (i.e uiwebview) when the orientation changes (i.e portrait to landscape or Viceversa).

Please give me any sample code or any suggestions for it.

Sanchit Paurush
  • 6,114
  • 17
  • 68
  • 107

5 Answers5

1

To resize the webview you have to write:-

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    webview.scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * someValue1, 
                                        scrollView.frame.size.height * someValue2);
}
ios developer
  • 3,363
  • 3
  • 51
  • 111
  • Exactly I am new for this field, but I wondered that If you don't use void then after it will returns the value to the main @shweta – SagarPPanchal May 14 '13 at 12:13
0

You can put your code in the following code block :

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if ([self isPadPortrait]) {
    // Your code for Portrait
    // set frame here  
} else if ([self isPadLandscape]) {
   // Your code for Landscape
   // set frame here 
}

and following code will take care of orientation change :

- (BOOL)isPadPortrait
{

    return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
            && (self.interfaceOrientation == UIInterfaceOrientationPortrait
                || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown));
}

- (BOOL)isPadLandscape
{

    return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
            && (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight
                || self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft));

}
Devang
  • 11,258
  • 13
  • 62
  • 100
0

You can set the autoresizingMask of scrollView and add this code to your .m file according to your requirement.

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * someValue1, 
                                        scrollView.frame.size.height * someValue2);
}
Robin
  • 10,011
  • 5
  • 49
  • 75
  • Will it resize of uiwebview which is the content of that uiscrollview – Sanchit Paurush Aug 23 '11 at 05:36
  • If you are making the views in xib file than you can test it by rotating the view otherwise you need to make a dump xib file to check what autoresizingMask that is required to your application – Robin Aug 23 '11 at 05:39
0

when ever the orientation changed

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration

{

// this delegate method will called if we set should auto orientation return yes;
when ever we changed orientation  so set frames.. 

}

for example

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration

{
    appDelegate.interface=interfaceOrientation;


    if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)

{

//  SET FRAMES FOR LANDSCAPE HERE       


}

    if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown || interfaceOrientation == UIInterfaceOrientationPortrait)

{ 
        //SET FRAMES FOR Portrait HERE              

}

}
Devang
  • 11,258
  • 13
  • 62
  • 100
Srinivas
  • 983
  • 9
  • 21
0

Here is a link to a similar question and their solution: Scale image to fit screen on iPhone rotation

They used a combination of AutoresizingMasks and ContentModes for both the ScrollView and, in their case, an ImageView, although I imagine the same solution would work for your WebView.

Community
  • 1
  • 1
superjessi
  • 1,790
  • 10
  • 17