Storyboard Autolayout & Design questions

Hey all,


I couldn't find a direct answer to my questions online, so I figured I'd come to yall. I apologize in advise if this question has already been asked, or if it is in the wrong forum. I am not new to programming (knowledge base includes good ol' fashion C & Assembly); however, I am new to Objective-C and more importantly Xcode.


Okay, so I have just gotten into developing a couple of apps, and I have come across a couple of big questions that will definitely save me a lot of time if I find the best way to do it now.


I am creating an app that has menu(s). Specifically when you click a button on the app a menu slides out and covers about 60% of the screen. On the menu is a list of options (buttons). So, right now I have the menu background (View) and buttons inside of the menu. Instead of programmatically creating the buttons and background view every time the menu button is clicked, the size of the views is expanded, and when it is clicked again it's width is set to 0 (so it appears that there is no menu open). When I run a simulation, everything works perfect, it seems fast, and I have no bugs.


So my questions:

(1) Is this a valid app design? Will creating an app that works like this cause it to run slower/faster. Is it better to programmatically create the menus & options every time the button is clicked?


(2) This is probably the biggest concern. Designing my app like this does not allow me to use "Auto Layout" or "Size Classes" (At least from what I have seen). So, if this is a valid way to design and create an app, will I be able to input something into my code that depending on what device or IOS the app is downloaded on- my app will reconfigure itself to fit the size of the device? I know I could very easily implement this code, but I would need my application to know what device the app is downloaded on.

(3) This question is a little bit off-topic than my other two. But is it possible to create an object on the Main.storyboard (ie a button with the height, width, X, & Y coordinates already set to how I want them, and then do something in Xcode to where I can see the code of the button if it was created programmatically (with the values already set to how I want them)?


I know these questions are very n00bish, but any help is great appreciated, and if you have any experience with similar app designing questions please feel free to comment on how you prefer to implement a "menu" and so forth.


Thanks again,

Snoz

Answered by junkpile in 70916022

1. Sure. From a usability standpoint, users don't find options that are hidden in slide out menus, but it's fine to do it that way and keep the view in memory if you want. Lots of apps do that. You can test the performance and memory usage but I think it's unlikely you'll see any issues.


2. You can easily use auto layout and size classes with a slide out menu. I use auto layout (not size classes yet) in a menu that is designed in IB and loaded from a XIB (see below). You could just as easily build your UI in code using auto layout - VFL or individual constraints (constraintWithItem:... etc.). Your view controller conforms to UITraitEnvironment so you can access its UITraitCollection and make decisions based on the current size class. There is also a traitCollectionDidChange callback to keep your view updated. To recap, you don't have to use IB to take advantage of auto layout or size classes though I personally find it easier to do so.


// Code to load a view from a XIB - this is from a helper class (NSObject) that manages my slide out menu
// May not be optimal design (this helper messes with parent's view hierarchy) but it works.
    [[NSBundle mainBundle] loadNibNamed:@"MyNibName" owner:self options:nil]; // This hooks up outlets to self if File's Owner is set up correctly
    self.view.translatesAutoresizingMaskIntoConstraints = NO; // View will be positioned using auto layout
    [someOtherView addSubview:self.view]; // someOtherView's view controller is responsible for adding constraints


3. No. Xcode doesn't have any code generation tool like that. Generally you would just build your button in IB, then make outlets for it and tweak it at runtime if necessary. You can also make outlets for layout constraints and adjust their constant, or add/remove them, at runtime.

Accepted Answer

1. Sure. From a usability standpoint, users don't find options that are hidden in slide out menus, but it's fine to do it that way and keep the view in memory if you want. Lots of apps do that. You can test the performance and memory usage but I think it's unlikely you'll see any issues.


2. You can easily use auto layout and size classes with a slide out menu. I use auto layout (not size classes yet) in a menu that is designed in IB and loaded from a XIB (see below). You could just as easily build your UI in code using auto layout - VFL or individual constraints (constraintWithItem:... etc.). Your view controller conforms to UITraitEnvironment so you can access its UITraitCollection and make decisions based on the current size class. There is also a traitCollectionDidChange callback to keep your view updated. To recap, you don't have to use IB to take advantage of auto layout or size classes though I personally find it easier to do so.


// Code to load a view from a XIB - this is from a helper class (NSObject) that manages my slide out menu
// May not be optimal design (this helper messes with parent's view hierarchy) but it works.
    [[NSBundle mainBundle] loadNibNamed:@"MyNibName" owner:self options:nil]; // This hooks up outlets to self if File's Owner is set up correctly
    self.view.translatesAutoresizingMaskIntoConstraints = NO; // View will be positioned using auto layout
    [someOtherView addSubview:self.view]; // someOtherView's view controller is responsible for adding constraints


3. No. Xcode doesn't have any code generation tool like that. Generally you would just build your button in IB, then make outlets for it and tweak it at runtime if necessary. You can also make outlets for layout constraints and adjust their constant, or add/remove them, at runtime.

>I am new to Objective-C and more importantly Xcode.


>So my questions:

>(1) Is this a valid app design?


In which case, (and on the assumption this is about iOS) the iOS Human Interface Guidelines may help lead you from where you are now.


Suggested sections: 'Design Basics' and 'Design Strategies'.

Thank for the quick answer junkpile!

I'm gunna go back through the app, and redesign it with autolayout format.


Kind Regards,

Snoz

Reading through it now, thanks!


Snoz

Storyboard Autolayout & Design questions
 
 
Q