UITextview text not displaying top lines after rotation in iOS7

I have an application containing a UITextview that displays static text. I used UITextview to get a scroll of text that is much longer than what UILabel can display. For some reason, the text in a UITextview under iOS 7 does not remain scrollable at the top after the rotation. This works as expected when running under iOS 6.

This can be shown by creating a project with a UITextview that focuses on a storyboard with margins of around 50. Then add constraints that snap the UITextview to the edges of the main view. Make sure the text box contains enough text to trigger scrolling:

enter image description here

, UITextview, . :

enter image description here

- .

, iOS 6. viewWillLayoutSubviews, :

[textView sizeToFit];
[textView layoutIfNeeded];

[textView setContentOffset:CGPointMake(0.0, 0.0)];

[textView scrollRectToVisible:CGRectMake(0.0, 0.0, 1.0, 1.0) animated:NO];

, . - , ?

+3
5

:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    [self.textView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO];
}

iOS 7.1.

+1

UITextView scrollRangeToVisible: viewDidLayoutSubviews. , .

-(void)viewDidLayoutSubviews {

    [self scrollToTop];
}

-(void) scrollToTop {
    [self.textView setScrollEnabled:NO];
    [self.textView scrollRangeToVisible:NSMakeRange(0.0f, 0.0f)];
    [self.textView setScrollEnabled:YES];
}
+1

. , UITextView (, this). , UITextView:

-(void) viewDidLoad{
    self.textView=[[UITextView alloc] init];
    self.textView.translatesAutoresizingMaskIntoConstraints=NO;
    [self.view addSubview:self.textView];

    NSDictionary* views = @{@"textView": self.textView};
    NSArray* vContrains=[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-50-[textView]-50-|" options:NSLayoutFormatAlignAllLeft metrics:nil views:views];
    NSArray* hContrains=[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-50-[textView]-50-|" options:NSLayoutFormatAlignAllLeft metrics:nil views:views];
    [self.view addConstraints:vContrains];
    [self.view addConstraints:hContrains];

}
-(void)viewWillLayoutSubviews{
   [self.textView layoutIfNeeded];
   [self.textView sizeToFit];
}
0

iOS 8.

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    self.textView.contentInset = UIEdgeInsetsMake(0,0,0,0);
}
0

:

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
  self.textView.scrollRectToVisible(CGRect(x:0,y:0,width:1,height:1),animated: false)
  self.textView.layoutIfNeeded()
  self.textView.sizeToFit()
}
0

All Articles