How to achieve full screen, landscape, and screen rotation on IOS Mobile phones

Source: Internet
Author: User

As a smart phone, IOS sometimes provides a good visual experience for users by Browsing webpages, reading e-books, and playing games in full screen mode, next I will share with you a simple code. First, add the navigation bar and toolbar on the view, and use the Image view as the subview of the current view. The principle is to hide the navigation bar and toolbar by triggering a button.

The Code is as follows:

HHLAppDelegate. h


# Import
 
  
@ Class HHLViewController; @ interface HHLAppDelegate: UIResponder
  
   
@ Property (strong,>
   

HHLViewController. h


#import 
    
     @interface HHLViewController : UIViewController@property (retain,nonatomic) UIButton *mBtn;@property (retain,nonatomic) UINavigationBar *myNavigationBar;@property (retain,nonatomic) UIToolbar *myToolbar;@end
    


HHLViewController. m


# Import "HHLViewController. h "@ interface HHLViewController () @ end @ implementation HHLViewController-(void) viewDidLoad {[super viewDidLoad]; UIImage * pImage = [UIImage imageNamed: @" 1.png"]; UIImageView * myImageView = [[UIImageView alloc] initWithImage: pImage]; // after this item is set, when the size of myImagView changes, the image proportion does not change. MyImageView. contentMode = UIViewContentModeScaleAspectFill; // After clipsToBounds is set to NO, images beyond the frame can still be drawn. MyImageView. clipsToBounds = NO; // After setting two constants to autoresizingMask, the width and height of the image will change as the parent view changes. autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; [self. view addSubview: myImageView]; self. mBtn = [UIButton buttonWithType: UIButtonTypeRoundedRect]; self. mBtn. frame = CGRectMake (150,300, 80, 40); [self. mBtn setTitle: @ "full screen" forState: UIControlStateNormal]; [self. mBtn addTarget: self action: @ selector (buttonPressed :) forControlEvents: UIControlEventTouchUpInside]; [self. view addSubview: self. mBtn]; self. myNavigationBar = [[UINavigationBar alloc] initWithFrame: CGRectMake (0, 0, self. view. frame. size. width, 50)]; [self. view addSubview: self. myNavigationBar]; self. myToolbar = [[UIToolbar alloc] initWithFrame: CGRectMake (0,420, self. view. frame. size. width, 60)]; // self. myToolbar. frame. size. width = self. view. frame. size. width; [self. view addSubview: self. myToolbar];}-(void) buttonPressed :( id) sender {self. mBtn. hidden = YES; [[UIApplication sharedApplication] setStatusBarHidden: YES]; self. myNavigationBar. hidden = YES; // [self. navigationController setNavigationBarHidden: YES animated: YES]; // self. tabBarController. hidesBottomBarWhenPushed = YES; // [self. navigationController setToolbarHidden: YES]; self. myToolbar. hidden = YES;} // implement rotation-(BOOL) shouldAutomaticallyForwardRotationMethods {return YES;}-(void) didReceiveMemoryWarning {[super didreceivemorywarning]; // Dispose of any resources that can be recreated .} -(void) dealloc {[_ mBtn release]; [_ myNavigationBar release]; [_ myToolbar release]; [super dealloc];} @ end



The implementation result is as follows:


The following figure shows the effect after you click the button:


This is a simple example. In the next article, I will share with you how to use gestures to achieve full screen and cancel full screen.

Related Article

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.