UITextView is a subclass of UIScrollView, so you can use its methods. If all you want to do is make sure it scrolls up, and then where the text is added, try:
[self.mainTextView setContentOffset:CGPointZero animated:NO];
EDIT: AutoLayout with any kind of scrolling quickly becomes fast. The fact that setting a fixed width decides is not surprising. If it does not work in -viewDidLayoutSubviews , this is odd. Setting the layout constraint manually may work. First create restrictions in IB:
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *textViewWidthConstraint; @property (weak, nonatomic) IBOutlet NSLayoutConstraint *textViewHeightConstraint;
and then in the ViewController
-(void)updateViewConstraints { self.textViewWidthConstraint.constant = self.view.frame.size.width - 40.0f; self.textViewHeightConstraint.constant = self.view.frame.size.height - 40.0f; [super updateViewConstraints]; }
You may still need setContentOffset in -viewDidLayoutSubviews .
(Another method would be to create a layout constraint for “equal” and “equal” heights between the text element and its supervision with a constant of “-40.” It only “equals” if the constant is zero, otherwise it is set by a constant, but since you can only add this restriction to a view that restricts both views, you cannot do this in IB.)
You may ask yourself if I should do this, what is AutoLayout? I studied AutoLayout in depth and this is a great question.
Mike Sand Jan 20 '15 at 19:11 2015-01-20 19:11
source share