Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9015277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:42:41+00:00 2026-06-16T03:42:41+00:00

I have a textView as a subview of a UIView , which is a

  • 0

I have a textView as a subview of a UIView, which is a subview of a scrollView according to this scheme:

-UIScrollView *scrollView
   -UIView *containerView
       -UITextView *textView
       -MKMapView *mapView
       -UIImageView *imageView

I have a problem during rotation, in the transition from portrait to landscape the TextView is shortened, and is no longer displayed part of the text that was visible before the rotation. In step contrary, from landscape to portrait work.Cosa can I do? The textView is created entirely in code, there isn’t an IBOutlet.

The UITextView is variable height, the contentSize in viewDidLoad is set as follows:

 - (void)viewDidLoad
 {
       [super viewDidLoad];
       //....
       self.textView = [[UITextView alloc]init];
       self.textView.backgroundColor =[UIColor clearColor];

       CGRect frame;
       frame = self.textView.frame;
       frame.size.height= [self.textView contentSize].height;
       [self.textView setContentSize:self.textView.contentSize];
       self.textView.frame = frame;
       NSLog(@"The contentSize of TextView is %@",NSStringFromCGSize 
                                                (self.textView.contentSize));

      //The contentSize of TextView is {0, 161032}
      //........


    }

The willRotateToInterfaceOrientation:duration looks like:

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

    if(deviceOrientation == UIInterfaceOrientationPortrait || deviceOrientation== UIInterfaceOrientationPortraitUpsideDown) {
        CGSize containerSize = CGSizeMake(768, 5000);

        self.scrollView.contentSize = containerSize;
        self.containerView.frame = CGRectMake(0, 0, 768, 5000);

        [self layoutPortrait];
    }
    else if (deviceOrientation== UIInterfaceOrientationLandscapeRight){
        CGSize containerSize = CGSizeMake(1004, 5000);

        self.scrollView.contentSize = containerSize;
        self.containerView.frame = CGRectMake(0, 0, 1024, 5000);

        [self layoutLandscape];
    }
    else if (deviceOrientation==UIInterfaceOrientationLandscapeLeft){
        CGSize containerSize = CGSizeMake(1004, 5000);

        self.scrollView.contentSize = containerSize;
        self.containerView.frame = CGRectMake(0, 0, 1024, 5000);

        [self layoutLandscape];
    }
}

And the two methods that handle frames rotation are:

 -(void) layoutPortrait{
        //...
        NSLog(@"the height of textView è %f", self.textView.contentSize.height);
        //the height of textView è 161032.000000

      self.textView.frame =CGRectMake(56, 490, self.viewImages.frame.size.width, self.textView.contentSize.height);
       //.....
 }
 -(void) layoutLandscape{
       //......
      NSLog(@"The height of textView è %f", self.textView.contentSize.height); 
      /*The height of textView è 2872.000000 
        (This after rotation from portrait to landscape)*/

      self.textView.frame = CGRectMake(170, 495, self.viewImages.frame.size.width, self.textView.contentSize.height);
      //......
 }

I want that the height of textView remain fixed during rotation. With UIImageView and MKMapView work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:42:43+00:00Added an answer on June 16, 2026 at 3:42 am

    Try this:

    • In viewDidLoad add this line after the init:

      self.textView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth;

    • At Handle frames rotation methods, change contentSize to frame:

      -(void) layoutPortrait{
          //...
          NSLog(@"the height of textView è %f", self.textView.contentSize.height);
          //the height of textView è 161032.000000
      
          self.textView.frame =CGRectMake(56, 490, self.viewImages.frame.size.width, self.textView.frame.height);
          //.....
      }
      -(void) layoutLandscape{
          //......
          NSLog(@"The height of textView è %f", self.textView.contentSize.height); 
          /*The height of textView è 2872.000000 
          (This after rotation from portrait to landscape)*/
      
          self.textView.frame = CGRectMake(170, 495, self.viewImages.frame.size.width, self.textView.frame.height);
          //......
      }
      

    That should do the trick (I’m in windows so i can’t try it)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a scrollView with a UIView as subview, which in turn has many
I have a UIScrollView, inside which I have some UILabels and a UITextView. The
I have textview which contains urls like www.google.com . for this textview a have
I have an UITextView as subview of UIView. I have placed the UIView in
I have added two textview in iphone by this way. I have two UITextView
I have a textView and text like This is the Simple Text with KeyWord
I have a TextView which i set the text using setText(). In properties, I
I have a form(table view) which contains textfields and textview as subviews,I need to
I have TextView in RelativeLayout, which works properly: <TextView android:id=@+id/tv_client_in android:layout_width=wrap_content android:layout_height=wrap_content android:layout_above=@+id/tv_label_client_out android:layout_alignParentLeft=true
I have a UITextView , which sets its text dynamically from an RSS feed.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.