Automatic rotation mechanism:
Not all iphones need to be supported in all directions. Apple recommends, however, that all ipad apps support all directions. iphone4 for 320*480iphone5, the size of the 320*568,retina screen a point is 4 pixels of the ipad for the 768*1024 point all the status bar (top display signal strength, time, power, etc.) for 20 points Automatic rotation implementation: 1. Define a constraint for the control so that it controls its position in different views 2. Manually adjust the position of the object within the view in code by 3. In IB, you design two different versions for the view, one for the horizontal screen, one for the vertical screen to tell iOS, and the rotation that our view supports , there are two ways: 1. The global, will affect the app all view emulator in the left and right rotation of the device's shortcut key command+, the command+-r key window layout status bar 20 points under the status bar, the upper left corner (0,0) position | | | | ———— the bottom right corner 320,548, note that is 548, because the status bar occupies 20 points 2. A private, global set of subsets, that is, if the global setting does not support landscape, the private setting is useless.
Uiviewcontroller
-(Nsuinteger) supportedinterfaceorientations
{
return Uiinterfaceorientationmaskportrait | Uiinterfaceorientationmasklandscapeleft;
}
Tip: Quick Comment program Fast conmand+/
Note that the Uiinterfaceorientationmasklandscapeleft: after rotation, the left edge is facing up.
Common combinations
Uiinterfaceorientationmaskall
Uiinterfaceorientationmaskallbutupsidedown
Uiinterfaceorientationmasklandscape
Using the constraint Design interface
Top blank front blank bottom blank back blank IB auto Create constraint object Drag to view edge, object Drag to nearby object, etc... The above constraint cannot be guaranteed to be in the middle in the horizontal time, need to use editor-"align-" Vertical Center in Container to establish the vertical middle constraint. Manual constraint creation, note that manually created constraints are coarse lines that can be deleted. Pin menu Width Fixed width height fixed altitude leading to Superview set to left constraint trailing space to Superview set to right constrain top Space to Superview build top constraint bo Ttom space to Superview establish the bottom constraint horizontal Spacing fixed controls horizontal spacing vertical Spacing fixed vertical spacing between controls Widths equally the selected control width is equal height Equal Ly selected control height equal Align menu horizontal center in Container horizontal middle vertical center in Container vertical middle rotation, with code refactoring view when using code to control the position of the control, the first thing to do is The AutoLayout feature that disables the Xib file opens the file inspector for the Xib file, which is called before the view rotation starts, and the overloaded
-(void) Willanimaterotationtointerfaceorientation: (uiinterfaceorientation) tointerfaceorientation Duration: ( Nstimeinterval) duration
This way, to modify the size and position of the control, different orientations, different settings
_bigbutton.frame = CGRectMake (20,20,280,280);
Viewdidload, the first time you display, you also need to set the
-(void) viewdidload
{
[Super Viewdidload];
UIApplication *application = [UIApplication sharedapplication];
Learn the direction of the app window using the Application status bar method
Uiinterfaceorientation curorientation = [Application statusbarorientation];
[Self dolayoutfororientation:curorientation];
}
Different ways to get screen orientation change: 1. Add an observer (Addobserver) 2 for the controller to uideviceorientationdidchangenotification notification. Direct use of Viewwilllayoutsubviews viewwilllayoutsubviews and willanimaterotationtointerfaceorientation:duration: Apart from the obvious differences , the former is called only when the landscape changes to portrait or portrait to landscape, while the latter is called in four directions. PS: Generally only use the former, because when the landscape becomes horizontal or vertical to vertical, there is no need to manually layout the interface. Another difference is that when a re-layout is required, the former is called, and the latter is called only when the screen is rotated, and the initial boot does not call the latter.
actually directly useViewwilllayoutsubviews, you don't have to rewrite viewdidload.
Willanimaterotationtointerfaceorientation:duration was removed from the IOS8.
Different directions, with different views of the export collection ...
No. 05 Auto-rotation and auto-sizing