Gravity Sensor screen Switch

Source: Internet
Author: User

1, remove StatusBar

In Info.plist Add Uistatusbarhidden set Boolean, set to Yes.

2, Horizontal screen

Continue adding uiinterfaceorientation settings in info.list uiinterfaceorientationlandscaperight Xcode 4.3.2 for inital interface Orientation set to Landscape (right home button) of course you input the above, Xcode will also correct for you, so both can!

3, Gravity sensing

Appdelegate inherits the Uiaccelerometerdelegate protocol and implements

Implement This method to get the lastest data from the accelerometer

-(void) Accelerometer: (uiaccelerometer*) Accelerometer didaccelerate: (uiacceleration*) Acceleration {

Use a basic low-pass filter to only keep the gravity in the accelerometer values{}

In

-(void) applicationdidfinishlaunching: (uiapplication *) Application {


}

Add to

Configure and start Accelerometer

[[Uiaccelerometer Sharedaccelerometer] Setupdateinterval: (1.0/kaccelerometerfrequency)];

[[Uiaccelerometer Sharedaccelerometer] setdelegate:self];

We can achieve gravity sensing.

4, automatically switch between the vertically.

-(BOOL) Shouldautorotatetointerfaceorientation: (uiinterfaceorientation) interfaceorientation//Support rotation
{

return YES;
}
-(void) Willrotatetointerfaceorientation: (uiinterfaceorientation) tointerfaceorientation Duration: (NSTimeInterval ) duration//When rotation occurs
{
F (self.interfaceorientation==uiinterfaceorientationportrait| | Self.interfaceorientation==uideviceorientationportraitupsidedown)
{
Horizontal Steering Vertical
}
}
-(void) Didrotatefrominterfaceorientation: (uiinterfaceorientation) frominterfaceorientation//rotation complete
{if (self.interfaceorientation==uiinterfaceorientationportrait| | Self.interfaceorientation==uideviceorientationportraitupsidedown)
{
It is currently in vertical screen mode
}
}

Toggle between horizontal Screens

-(BOOL) Shouldautorotatetointerfaceorientation: (uiinterfaceorientation) interfaceorientation//Support rotation

{

if (interfaceorientation = = uiinterfaceorientationlandscaperight)

{

return YES;

}

else if (interfaceorientation = = Uiinterfaceorientationlandscapeleft)

{

return YES;

}

return NO;

}

/////////////////////////////////////////////////////////////

The following has not been tested

Using gravity sensing, determine the direction of the phone, and then Set [uiapplication sharedapplication].statusbarorientation = Uiinterfaceorientationlandscaperight, As well as uiinterfaceorientationportrait, can be done according to the direction of the different mobile phone pop-up or Vertical screen dialog box, including the dialog box containing the input box keyboard can also be automatically rotated

/////////////////////////////////////////////////////////////

5, power on screen horizontal screen

Default-landscapeleft.png
Default-landscaperight.png
Default-portrait.png
Default-portraitupsidedown.png

Gravity Sensor screen Switch

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.