Why does my button stop working when it is placed too low on my view controller? - ios

I have an app that works fine on a 4 inch iPhone. However, when I test the app on the 3.5 inch iPhone, my buttons near the bottom of the view don't work anymore. I have buttons higher up that are still working fine. I tested this out on the 4 inch simulator - when I put a button even closer to the bottom, it wouldn't work. By not working, I mean they are no longer clickable.
Is there something thats stopping me from operating too low on a view? I currently use a container view with a scroll view which points to my view controller.

Hard to tell.
If you are working with Interface Builder, you can't even show us what's your setup. This doesn't help
My first guess is that you either have an invisible element on top of your buttons, or that something funny is happening with the content view of your scroll view.
Try to place your buttons directly in the parent/root view. If that works, bring them back to their original position in the view hierarchy, one level at a time. This should give you an idea of where they stop working, and what might be causing it.

Related

Interface builder position off screen

I have a container view showing a sidebar which is pinned to the main views leading edge. The sidebar is initial visible which is fine for iPads however I would like it to be hide initially for smaller devices. To do that I need to set the side bars trailing edge constraint to be (0 - its own width)
As far as I can see this is not possible in the interface builder. I have tried to do it in the viewDidLoad, checking if the device is an iPhone before doing self.sidebarX.constant = -self.sidebar.frame.width. This fails because viewDidLoad has not set up the views yet so the width is wrong. I also tried to do it in viewDidLayoutSubviews however the user sees the sidebar disappearing which isn't nice. I am sure there must be a common way of dealing with this?
I finally worked it out. viewDidLayoutSubviews was the correct place to be doing this. At first when I tried it, it was showing the sidebar slide away as the view controller loaded. It turns out this is because I was calling my closeSidebar method which animates the side bar moving off screen. Changing this so it just sets the view off screen and adding a check to ensure this only done once on first load (as viewDidLayoutSubviews is called multiple times) does the job of hiding the the sidebar for certain devices without anyone seeing it happen.
You can set this using xcode adaptative layout:
You can set the different position for all different screen types here, changing the constraints, positions, sizes to each different type you need.
You can install the layout of one object in different screen types using the dialog below:
Have a look in this 2 parts tutorial from raywenderlich part 1 part 2

Elements overlaying another making it disappear

Pitures makes a 1000 words:
This is how it looks in storyboard (IB):
And in simulator:
So I was working with this and it was working fine, until I started applying constraints. Then suddenly my arrow disappeared. Took me a good 20 minutes to figure out it had decided to hide behind my button. My view hierarchy implies that the arrow is still drawn after the button, so I don't know why it is hiding like that (also because it was working correctly before constraints added). How do I fix this in IB and/or programmatically?

UIViewController completely out of place on the screen

I am putting together a sample iPhone app for practice. It is a drill-down interface with doctors who have patients who have prescriptions and visits using Core Data and a story board.
Everything was going great until I started on the Edit/View doctor screen. Because this screen is triggered by a button in the UITableViewCell, it seemed that there was no way to create a segue on the story board to an edit/view screen because the buttons in the cells are dynamically created.
I decided to make a separate UIViewController custom class and I let Xcode generate the XIB for me to make sure I did not mess up anything. I presented the edit/view view controller by pushing onto the navigation controller. The problem is that the contents of the edit/view screen were nearly completely off the screen. With my first attempt, a navigation bar I put at the top appeared at the very bottom of the screen in the simulator with all of the rest of the text fields and labels not showing at all.
I then created another view controller with xib, specifying iPhone only and simply put a label with "Hello" in the center of the view. When I ran the simulator, "Hello" was centered vertically, but was all the way to the right of the screen with only "He" showing. I tried played with anything I could find to play with, but nothing fixes it. I am not trying to do anything unusual. I want to do everything in the usual accepted way.
Also, it seems like Interface Builder makes the views look like big square iPad screens even when I have specified iPhone. I did check the frame dimensions and it was wxh = 600x600.
Thank you for your help.
It occurred to me to search for 600x600 and it seems that this is the new UIView that Interface Builder provides by default. Because there are many screen sizes, Constraints are apparently mandatory now.
My edit/view form was completely fixed by viewing the XIB and going to:
Editor->Resolve Auto Layout Issues->Add Missing Constraints.

Interface Builder strange interface error

I am having a strange error on my builds. When i design my view in interface builder, everything looks fine. As soon as I run my app on my iPhone, everything messes up. The buttons I use are smushed into the top left corner of the screen, and the font size does not change, even though I have proper settings for all screen sizes. The labels A and B work fine though. This is very puzzling to me. This is not the only view which I am having this error with. Here are pictures to detail my problem further:
This is the view I see in interface builder.
The view I see when I run my app on my phone is quite different.
Why am I seeing the views so differently? Why are the buttons being smushed to the top right of the screen when I run my app?
You probably don't have sufficient constraints on those buttons for the runtime to know how to place them. Usually constraint issues will show up at build/design time with a yellow or red circle in the tree view for the storyboard/xib. Try using "reset to suggested constraints"

Developing on an iPod iTouch - UIView Issues

So I've been using this site for a lot of my questions. I'm very good with Googling problems and debugging even the worst error code, but this is something rather basic that I'm not able to figure out.
My UIView compared to what I actually see on the iTouch has always been a bit different. I'm not sure if this is xCode's IB just having larger graphics for its buttons, but in general there is this 20px height difference, to the point where if I set a button at the bottom of the UIView, it gets cut off. (I thought it was supposed to be 320x460..)
Normally I shrug this off because it hasn't been an issue till I've started to put scrolling into place with the login screen. xCode claims my view is 320x548, my app says its 320x480. If I resize my scroll size to 320x480, the view shrinks on the iTouch, leaving a large gap.
I have been using UIViews in the IB rather then a ViewController because I'm subviewing mixed with some nav control.
Is there something that I'm doing wrong?
http://oi49.tinypic.com/rrnjit.jpg (when first loading)
http://oi50.tinypic.com/j8matu.jpg (scrolling down about 20 px..)
You need to make correct use of springs and struts or Auto Layout. You are probably designing your app for the 4 inch screen - in your Storyboard, there is an option to see how it would look on a 3:5 inch screen. Press that.
For more info, Google Auto Layout.

Resources