1

Tools Specification:

  • OS X Yosemite 10.10
  • Xcode 5.1.1

Today I found one weird issue (Or may be if i'm wrong with new specialisation or something else. Please make me correct if anything is wrong).

I created project using Xcode 5.1.1 for iOS 7.1 OS with Storyboard support. Everything here is default. Now just drag and drop UITextView into view of UIViewController (It is embedded in UINavigationController more precisely).

Here all properties of UITextView are default except background color (Change to highlight border of UITextView). I see that the default text in UITextView goes bottom when I change its height. Also left some space on top and than text is rendered. See the below image:

Misleading space at top

Run application to check this also in simulator. And it shows extra space on the top of UITextView.

enter image description here

I also did the same in Xcode 6.0.1 to double sure that this is not default behaviour. And it is perfect in Xcode 6.0.1, there were no extra space on top of content of UITextView.

enter image description here

Spotlight:

I never did face this issue before. I updated Mac OS Yosemite two days ago (If its relevant to the Mac OS).

Also one thing is to be note that if I remove embedded UINavigationController than it works normal.

So is it related to OS? OR Do I miss something, I mean Apple introduce or change any behaviour?

Note: There is no any constraints. Just drag and drop UITextView to view.

Kampai
  • 22,848
  • 21
  • 95
  • 95

2 Answers2

1

EDIT: Just updated to XCode6.1 and I am building onto iPad with iOS7.1 - THE SAME ISSUE PERSISTS!

I think it is a bug in XCode5.1.1, here is what I found, may be it will help you, it did help me.

EDIT: Hey, just discovered that UITableView does exactly the same, it appears scrolled down if it is 1st in a list in interface builder, same trick cures it.

Here I have my textview 1st in the list in interface builder: enter image description here

and it is scrolled down when you run the app: enter image description here

However, if I move my textview below the others: enter image description here

It shows up in the app all right: enter image description here

So, just make sure none of the textviews (or tableviews) are 1st in the list in interface builder! Seems like real bug to me, will log it in with Apple.

Boris Gafurov
  • 1,427
  • 16
  • 28
  • What about only one `UITextView`? Is it leave extra top space? – Kampai Nov 06 '14 at 06:51
  • @Kampai - yep, if it is the only view it shows scrolled down, to use this trick need at least 1 more, say add a dummy UILabel and set it 1st in the list and make it hidden, that should do it. – Boris Gafurov Nov 06 '14 at 14:45
  • I filed it as a XCode5.1.1 bug with Apple Bug Reporter, will see what they have to say, most likely - wait till next version of XCode that will have more bugs lol – Boris Gafurov Nov 06 '14 at 15:13
0

I think you can fix this by setting the property contentOffset as follows:

yourTextView.contentOffset = CGPointZero

This allow you to set the text at top of the UITextView's frame.

jomafer
  • 2,655
  • 1
  • 32
  • 47
  • But if i remove embedded `UINavigationController` from `UIViewController` it works. And why i need to write this extra line of code. It should be default right as like in iOS 8? – Kampai Nov 06 '14 at 06:50
  • I think that the UITextView considers that extra spacing to place the UINavigationBar. I don't know the real reason for that, but I think that my solution could fix that. Have you tried it? – jomafer Nov 06 '14 at 09:14
  • No. If so then same thing must be happen in iOS8 too. – Kampai Nov 06 '14 at 11:12
  • @jomafer - hi, I tried yours - if I put your code in viewDidLoad or viewWillLoad - does not work, though it works if I put it in viewDidLoad. So it has to be visible, than it will adjust it. And you kinda see it adjusting, kinda weird text scrolls up on its own. – Boris Gafurov Nov 06 '14 at 15:06