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.