I'm deep in trying to create a fully customized layout for an application that I'm working on. What I'm doing is creating sub-classes of labels, views, and buttons and placing those into the main application class, which will hold the whole of my application.
I guess my problem is, it seems to be a lot of calculating the position, size, and orientation of the views and buttons I place. It seems simple enough to just give a control an X-Y position and a width-height size and let it go, but when I have to worry about portrait orientation versus landscape orientation, and how I have to calculate, store, and recall a different frame for every view and button I do simply because I cannot set the size and position to be something different...it starts to become a mired headache. Add to this fact that I have a lot of views and such that are dependent on each other for their sizes. Such that a header view has two buttons to the left and right of it and if the header's size changes, the buttons need to dynamically change with it...
I guess I'm starting to get lost and I need to know if this is really the best and true way to make a completely custom interface. Holding a store of CGRects in each view just to tell it what to do when the iPad flips seems redundant. Or is it that all of the work I'm doing placing and setting actions to fire when the orientation of the screen changes something that IB is supposed to be doing and by creating my own custom interface, I'm having to do the work instead?
Look into making a custom container view. Then you can swap out views and have all the callbacks work properly. Check out my custom interface in Oneshare
__________________
What do you have to share? Share and view pics Oneshare
I'm deep in trying to create a fully customized layout for an application that I'm working on. What I'm doing is creating sub-classes of labels, views, and buttons and placing those into the main application class, which will hold the whole of my application.
I guess my problem is, it seems to be a lot of calculating the position, size, and orientation of the views and buttons I place. It seems simple enough to just give a control an X-Y position and a width-height size and let it go, but when I have to worry about portrait orientation versus landscape orientation, and how I have to calculate, store, and recall a different frame for every view and button I do simply because I cannot set the size and position to be something different...it starts to become a mired headache. Add to this fact that I have a lot of views and such that are dependent on each other for their sizes. Such that a header view has two buttons to the left and right of it and if the header's size changes, the buttons need to dynamically change with it...
I guess I'm starting to get lost and I need to know if this is really the best and true way to make a completely custom interface. Holding a store of CGRects in each view just to tell it what to do when the iPad flips seems redundant. Or is it that all of the work I'm doing placing and setting actions to fire when the orientation of the screen changes something that IB is supposed to be doing and by creating my own custom interface, I'm having to do the work instead?
You can use IB to manage custom objects. I do that all the time.
Just drag UIViews, labels, buttons, etc. onto your screen design. Use container views to group other views like a header with buttons on either side. Learn how to use the IB "struts and springs" to get your views resizing the way you want.
Once you get your layout the way you want it, and resizing the way you want it, select the objects and change their class to your custom classes. IB will still manage them, since they should be subclasses of UIView/UIButton/UILabel, whatever.
It's much, much easier to manage layout and orientation changes in IB than it is in custom code. As you're learning, controlling all that stuff in code is a huge amount of work.
You may have to add some custom code to adjust the rotation behavior or some of your view groups, but you should be able to get really close with clever use of grouping and "struts and springs" controls.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
You can use IB to manage custom objects. I do that all the time.
Just drag UIViews, labels, buttons, etc. onto your screen design. Use container views to group other views like a header with buttons on either side. Learn how to use the IB "struts and springs" to get your views resizing the way you want.
Once you get your layout the way you want it, and resizing the way you want it, select the objects and change their class to your custom classes. IB will still manage them, since they should be subclasses of UIView/UIButton/UILabel, whatever.
It's much, much easier to manage layout and orientation changes in IB than it is in custom code. As you're learning, controlling all that stuff in code is a huge amount of work.
You may have to add some custom code to adjust the rotation behavior or some of your view groups, but you should be able to get really close with clever use of grouping and "struts and springs" controls.
I'm really hoping the auto layout will make its way from the Cocoa side into Cocoa Touch as well, it looks so awesome. Things like these would be a lot simpler with it. Perhaps we should all file bug reports requesting it?
You mentioned: "Or is it that all of the work I'm doing placing and setting actions to fire when the orientation of the screen changes something that IB is supposed to be doing and by creating my own custom interface, I'm having to do the work instead?"
I don't think IB does that for you. I think the Object does that for itself. I could be wrong here, I'm trying to learn to develop without IB. I'd rather do things in code.
But, my understanding of IB is that it's just a screen layout tool. After you layout your screen, you make all the connections and it's very easy to see what the screen will look like and to make changes.
But I don't think IB has anything to do with changing position when you rotate the screen.
If your using stock objects, isn't there settings for how the object behaves when the screen is rotated?