#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];
//设置此项后,当myImagView的尺寸发生变化时,其中的图像比例不会改变。
myImageView.contentMode = UIViewContentModeScaleAspectFill;
//将clipsToBounds设置为NO后,超出frame以外的图像仍然可以绘制。
myImageView.clipsToBounds = NO;
//向autoresizingMask设置两常量后,将随着母体view的变化改变图像的宽度与高度
myImageView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
[self.view addSubview:myImageView];
self.mBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
self.mBtn.frame =CGRectMake(150, 300, 80, 40);
[self.mBtn setTitle:@"全屏" 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;
}
//实现旋转
- (BOOL)shouldAutomaticallyForwardRotationMethods
{
return YES;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc
{
[_mBtn release];
[_myNavigationBar release];
[_myToolbar release];
[super dealloc];
}
@end
实现的效果下图所示:
点击button后效果如下图所示:
简单的分享就到这里,下一篇我会给大家分享一下通过手势来实现全屏,和取消全屏。