Re: Alternative to Auto Layout?


Dave
 

Hi,

As I said, the board view is working ok with Auto Layout and also the Frame of the Player View is also working, but that’s the easy bit!

I want to display the following information:

Game: 999                Round: 999

Player:  XXXXXXXXXXXXXXXX

Score: 999                  Total: 999

   Piece Picked  Piece Played
 
<16x16> <16x16>   <16x16> <16>

                    My Pieces
[H Scroll View of Pieces] (Views containing images)

               Opponents Pieces

[H Scroll View of Pieces] (Views containing images)


I’ve sort of got this working with Auto Layout but its so complex and if I want to do the slightest change or worse still add to components of left view, I have to change loads of constraints and then if you are lucky it might work, most of the time it send something else off to the wild-beyond and screws up the initial value. 

I want something I can easily change which using manual layout is easy. 

Apart from anything else, I reckon there are at least 100 constraints just to do the above, I can’t see how this can be efficient, especially as manual layout is sooooo fast.

Can anyone see anything wrong of doing it the way I proposed? e.g. Reading the Root View of the Root View Controller to find it size and then scaling accordingly?

In IB, add two views to controller_view and position them so that their common edges touch and that the other edges are aligned with controller_view. Click on the "add new constraints" button and add constraints to enforce the edge positioning for player_view and then for board_view. Once you apply them you will notice that IB is flagging an error because there are not enough constraints to specify the widths of the two views. Ignore it.

I’ve not bothered with separate View Controller, I have one Game Controller, which controls both views, the reason for this is that the Game VC is a delegate of the Game Engine, and makes calls to it, in this case it needs access to both Views…...

All the Best
Dave



On 4 Jul 2017, at 17:33, Steve Christensen <punster@...> wrote:

It sounds like a really easy task. Unless there is something else you haven't mentioned the basic idea is to have two views that sit side-by-side, where the ratio of widths is 1:2. If so then you end up with a view hierarchy like this:

controller_view
player_view
board_view

In IB, add two views to controller_view and position them so that their common edges touch and that the other edges are aligned with controller_view. Click on the "add new constraints" button and add constraints to enforce the edge positioning for player_view and then for board_view. Once you apply them you will notice that IB is flagging an error because there are not enough constraints to specify the widths of the two views. Ignore it.

Next, make sure that player_view and board_view are both selected, click on the "add new contraints" button again and click the "equal widths" checkbox, then apply the constraint. IB should now resize the two views so that they have equal widths. You're almost there.

Finally, making sure that just player_view is selected, edit the "equal height to: board_view" contraint and change the multiplier to 2. All done.

Now the views should track the actual screen size, keeping their respective widths in proportion to 1/3 and 2/3 of the screen width.


On Jul 4, 2017, at 4:36 AM, Dave <dave@...> wrote:

Hi All,

Does anyone know of an alternative for Auto Layout.

I find myself wasting so much time with it as to be ridiculous, so I’d like to get away from it if possible.

I’m writing a Game for iPhone, iPad and Mac. I’ve decided to have 3 separate projects for these rather than lump it all into one giant project. The Game Engine will port with no compile problems onto all 3 platforms so all I need to do is the UI for the 3. I’m concentrating on the iPhone for now.

The game doesn’t really have a massive UI. There is a Game Setup screen (Window) and a Game Play screen. I’m only worrying about the Main Game Play Screen for now, this contains a left “Player” Area and a right Board area. The Player Area is 1/3 of the width of the screen (this App is landscape only) and the board takes up the other 2/3’s. The board was quite easy to get working with a bunch of nested Stack Views, but the rest of Ui is proving to be too hard to do with AU.

When I started this project, I decided to give AU a try (I’d previously tried to get on with it twice before) and had hoped that the tools would have improved enough to make it usable and practical to use, however, sadly this isn’t the case, so its better to back out now rather than further down the line.

So, how to lay this out without AU?

I’ve know how I've done this in the past, and adapting the technique in this case would mean:

1. Picking a Nominal device for the initial design, I’d pick iPhone 5s in this case, take the Size of the Root View 568, 320 which would be a constant in the App.
2. The App would read the size of the Root View and set a scaling factor.
3. The App would create and position the views using this scaling factor when it starts up.

I agree its not as flexible as using AU, but it a whole lot quicker and much more maintainable since you are not at the mercy of XCode/IB.

Any one have any other ideas of how to do this?

All the Best
Dave



Join cocoa@apple-dev.groups.io to automatically receive all group messages.