Imitation QQ video Full screen interface rotation implementation

Source: Internet
Author: User

//Implementation Effect: interface support system auto-turn screen and click to turn screen//VIEWCONTROLLER.M//rotatotest//copyright©2016 year Yaoyao. All rights reserved.//1. Turn off the system auto-turn screen//2. Get the device orientation, set the turn screen,//3. Click the button to set the Turn screen#import "ViewController.h"#import<UIKit/UIKit.h>#import<CoreGraphics/CoreGraphics.h>@interfaceViewcontroller () {floatwidth; floatheight;} @property (nonatomic,retain) Uiimageview*ImageView;@end@implementationViewcontroller- (void) Viewdidload {/** * UIImage Object*/UIImage*image = [UIImage imagenamed:@"000.jpg"]; Self.imageView.image=image; //Set Picture RangeCGFloat Imageh =Image.size.height; CGFloat Imagew=Image.size.width; CGFloat ImageX=0; CGFloat Imagey=0; Self.imageView.frame= CGRectMake (ImageX, imagey, Width, -); Self.imageView.userInteractionEnabled=YES;            [Self.view AddSubview:self.imageView]; //equivalent to the full screen button above QQ videoUIButton *BTNL =[UIButton Buttonwithtype:uibuttontypecustom]; Btnl.frame= CGRectMake ( -, -, Max, -); [Btnl settitle:@"Click to Zoo"Forstate:uicontrolstatenormal]; Btnl.backgroundcolor=[Uicolor Bluecolor];    [Btnl addtarget:self Action: @selector (Btnlclick) forcontrolevents:uicontroleventtouchupinside];        [Self.imageview ADDSUBVIEW:BTNL]; //the equivalent of the QQ Video full screen interface on the back buttonUIButton *BTNP =[UIButton Buttonwithtype:uibuttontypecustom]; Btnp.frame= CGRectMake ( $, -, -, -); [BTNP settitle:@"Click on the vertical screen"Forstate:uicontrolstatenormal]; Btnp.backgroundcolor=[Uicolor Bluecolor];    [BTNP addtarget:self Action: @selector (Btnpclick) forcontrolevents:uicontroleventtouchupinside];        [Self.imageview ADDSUBVIEW:BTNP];    [Super Viewdidload]; //additional setup after loading the view, typically from a nib.}//support Rotation (turn off the auto-turn screen when manually turning the screen)-(BOOL) shouldautorotate{returnNO;}//Supported direction (pro-Test: This method is still called when the previous method returns no)-(Uiinterfaceorientationmask) supportedinterfaceorientations{NSLog (@"Supportedinterfaceorientations called the"); returnuiinterfaceorientationmaskportrait | Uiinterfaceorientationmasklandscapeleft |Uiinterfaceorientationmasklandscaperight; }-(void) btnlclick{[[UIApplication Sharedapplication]setstatusbarorientation:uideviceorientationlandscapeleft    Animated:yes]; CGFloat Duration=[UIApplication sharedapplication].statusbarorientationanimationduration;    [UIView Beginanimations:nil Context:nil];    [UIView setanimationduration:duration]; //Here you set the View.transform to match the size of the rotation angle. Self.imageView.transform =cgaffinetransformidentity; Self.imageView.transform= Cgaffinetransformmakerotation (m_pi/2.0); Self.imageView.frame= CGRectMake (0,0, width, height); [UIView commitanimations];}//Click Back to Vertical screen-(void) btnpclick{[[UIApplication sharedapplication]setstatusbarorientation:uideviceorientationportrait animated:    YES]; CGFloat Duration=[UIApplication sharedapplication].statusbarorientationanimationduration;    [UIView Beginanimations:nil Context:nil];    [UIView setanimationduration:duration]; //Here you set the View.transform to match the size of the rotation angle. Self.imageView.transform =cgaffinetransformidentity; Self.imageView.transform= Cgaffinetransformmakerotation (0); Self.imageView.frame= CGRectMake (0,0, Width, -);    [UIView commitanimations]; }- (void) Handledeviceorientationdidchange: (uiinterfaceorientation) interfaceorientation{//1. Get the current device instanceUidevice *device =[Uidevice Currentdevice]; /** 2. Gets the direction of the current device, the device's direction type is integer * * must be called after the Begingeneratingdeviceorientationnotifications method, this orient The Ation property is valid, otherwise it has been 0. Orientation is used to determine the orientation of the device, regardless of the application UI direction * * @param device.orientation **/        Switch(device.orientation) { Caseuideviceorientationfaceup: {NSLog (@"the screen is lying flat"); }                         Break;  CaseUideviceorientationfacedown:nslog (@"flat down on the screen");  Break; //system can not judge the current device direction, there may be a bias         CaseUideviceorientationunknown:nslog (@"Unknown Direction");  Break;  Caseuideviceorientationlandscapeleft: {NSLog (@"screen left Sideways");            [[UIApplication Sharedapplication]setstatusbarorientation:uideviceorientationlandscapeleft Animated:YES]; CGFloat Duration=[UIApplication sharedapplication].statusbarorientationanimationduration;            [UIView Beginanimations:nil Context:nil];            [UIView setanimationduration:duration]; //Here you set the View.transform to match the size of the rotation angle. Self.imageView.transform =cgaffinetransformidentity; Self.imageView.transform= Cgaffinetransformmakerotation (m_pi/2.0); Self.imageView.frame= CGRectMake (0,0, width, height);                    [UIView commitanimations]; }                         Break;  Caseuideviceorientationlandscaperight: {NSLog (@"Screen Right Horizontal");            [[UIApplication sharedapplication]setstatusbarorientation:uideviceorientationlandscaperight Animated:YES]; CGFloat Duration=[UIApplication sharedapplication].statusbarorientationanimationduration;            [UIView Beginanimations:nil Context:nil];            [UIView setanimationduration:duration]; //Here you set the View.transform to match the size of the rotation angle. Self.imageView.transform =cgaffinetransformidentity; Self.imageView.transform= Cgaffinetransformmakerotation (-m_pi/2.0); Self.imageView.frame= CGRectMake (0,0, width, height);        [UIView commitanimations]; }             Break;  Caseuideviceorientationportrait: {NSLog (@"Screen Upright");            [[UIApplication sharedapplication]setstatusbarorientation:uideviceorientationportrait Animated:YES]; CGFloat Duration=[UIApplication sharedapplication].statusbarorientationanimationduration;            [UIView Beginanimations:nil Context:nil];            [UIView setanimationduration:duration]; //Here you set the View.transform to match the size of the rotation angle. Self.imageView.transform =cgaffinetransformidentity; Self.imageView.transform= Cgaffinetransformmakerotation (0); Self.imageView.frame= CGRectMake (0,0, Width, -);                    [UIView commitanimations]; }             Break;  CaseUideviceorientationportraitupsidedown:nslog (@"screen upright, up and down upside down");  Break; default: NSLog (@"not recognizable");  Break; }    }-(void) Viewdidappear: (BOOL) animated{/** * Start generating device rotation notifications*/[[Uidevice Currentdevice] begingeneratingdeviceorientationnotifications]; /** * Add Device Rotation notification * * @param handleDeviceOrientationDidChange:handleDeviceOrientationDidChange:descriptio n * * @return return value Description*/[[Nsnotificationcenter defaultcenter] addobserver:self selector: @selec Tor (handledeviceorientationdidchange:) Name:uideviceorientationdidchangeno TificationObject: nil]; }-(void) Viewdiddisappear: (BOOL) animated{/** * Destroy device rotation notification * * @return return value Description*/[[Nsnotificationcenter Defaultcenter] removeobserver:self name: UideviceorientationdidchangenotificationObject: nil]; /** * End Device Rotation notification * * @return return value Description*/[[Uidevice currentdevice]endgeneratingdeviceorientationnotifications]; }- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}#pragmaLazy Loading-(Uiimageview *) imageview{if(!_imageview) {_imageview=[[Uiimageview alloc] init]; }    return_imageview;}@end

Imitation QQ video Full screen interface rotation implementation

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.