Adjust Center of Measure in Xcode 6

2019-02-25 17:51发布

问题:

In the new "Xcode 6" the ability to change the center of measure of a button is missing.

In Xcode 5: http://imgur.com/jWHJp4v

Xcode 6: http://imgur.com/rsNayVZ

When I put an item (like a button or label) somewhere, I am unsure of the center, so my code that deals with the item is incorrect.

The "center" shown here in Xcode 6 is measured from the top left of the item, not the actual center.

How should I fix this so it is measured from the center like here, in Xcode 5?

回答1:

If your layout isn't too complex you can "Pin" your button or view to the top or bottom, sides, etc.

Or you can do your constraints manually here:

The first method works really well and is super easy! I had a similar problem as you looking for tools that have been left out in Xcode 6 and found this wonderful tutorial on Auto Layout:

http://www.raywenderlich.com/50317/beginning-auto-layout-tutorial-in-ios-7-part-1

If you are trying to center it I would click on the button or view you are working on and look at the size inspector here:

Look at where I circled and make sure that the bottom space and the top space are equal to the same amount (mine aren't equal), but that should give you the center.



回答2:

You can't “fix it”. That control is gone in Xcode 6. I suspect they removed it to encourage you to use constraints instead of setting frames directly. You can use constraints to pin the center, right, or bottom of a view.



回答3:

It's driving me crazy that the origin widget has been removed. It has made the placement of any object relative to another very difficult. I always use auto layout and I'm not sure how this improves it. Also, I'm not sure I follow the logic of improving a feature by making it more difficult to use. In the past, it was very helpful to set the "anchor point" of the origin and then adjust the object's position or size and have the frame grow on the unanchored sides. Now i have to break out the calculate and add position + size and then add buffer space to figure out where next object should start. And if I adjust the first object's frame in any way I need to break out the calculator again. Once you have a few objects that are relative to each other, it becomes vary painful to tweak any object's frame without having to recalculating everything.

As a side note, the removal of the ability to delete a constraint right in the size inspect is also a confusing choice. Instead we have to go through the document outline and manually delete them there. This is not a big deal for the size constraints as they are keep in the object's sub-directory however finding edge related constrains is much more difficult as they are grouped with the rest of the edge constrains and can be difficult to find. Again, is this an example of encouraging / improving auto layout? Very frustrating!



回答4:

The feature has been removed from Xcode. I believe this is to account for the various sizes of devices now available, and as a result, the use of constraints is the way to go.



回答5:

If you are using auto layout then this two will help you place you control in center for all the view different size of devices.
simple:
http://technet.weblineindia.com/mobile/using-auto-layout-in-xcode-6-for-universal-ios-app-development/ Advance:
http://www.youtube.com/watch?v=G53PuA_TlXk&feature=youtu.be&list=UUtc1Jt_UTPsXpAGtvlr0nUQ


Apple has removed this feature as there are 4 different size of devices only for iphone and it would be difficult to set frame for all controller and will increase the length of code and will become a tedious task as it check's the size of device and then set frame so in XCode 6.0.1 we need to use auto layout + size class and prepare our view based on the constraints set in storyboard or Xib.

Hope the above link's will help in solving your problem.