Being new to iOS after the Swift programming language was announced, it was a pain for me to find a fix to why the ScrollView always places an extra space at the top of the child view even though I already placed constraints.

I mean, that is what constraints are for, right? Check the image below. The ScrollView has a background color that looks pink and orange while its child View has a white background.

ios_uiscrollview1

See the extra space at the top? I tried to set combinations of alignment and spacing constraints to no avail. I wasted almost a half day for this till I decided to try my luck looking in Google searches for a solution.

And the solution is?

adjust_scrollview_insets

  • Click your ViewController in the tree list on the left
  • Select the Attribute Inspector
  • Under the View Controller area, go to the label that says Layout : Adjust Scroll View Insets
  • Uncheck that and recompile.

Now the extra top space will disappear.

ios_uiscrollview2

 

Since I am still new to iOS, I do not understand the purpose of this option. There are constraints in the first place so what is this for? Regardless, to avoid this problem, this is the only solution that works without doing any coding.

This typically works in iOS7 and later. However, I read that in iOS6 it still leaves a gap. I have not tested this but you could try this option that user Anooj VM provided in the Stack Overflow forum.

The fix is to implement within the viewDidLoad() by adding this line of code:

 

Typically, table views in iOS apps do something after a user clicks on a row. In ios Swift, you need to add the tableView function that has the didSelectRowAtIndexPath parameter in it.

Then, use the segue ID that you set in the storyboard and call self.performSegueWithIdentifier() to go to the next view.

One might think the quickest and easiest way to hide a Surface object in Famo.us is to set its opacity to transparent.

While true, you will also have to set its other properties like text color and such which is a hassle. Okay, so if you do not find that a hassle, there is another problem.

All input events like mouse clicks will be absorbed by this surface. So if you intentionally wanted to hide the Surface because the you want the other Surface below it to receive events, it will not work.

What I did was to make use of the Modifier that was used to add the Surface to the View. It has a setOrigin method that you can take advantage of to move this Surface object away from the user’s screen.

Say, setOrigin(0.5, 0.5) moves the Surface object to the center of the screen. You can do setOrigin(-0.5, -0.5) to move it out of the user’s screen making the user think that you actually hid the Surface object when in fact, you just moved it.

To show the Surface object back, just set the values to non-negative. That’s it!

Related Posts Plugin for WordPress, Blogger...