您的位置:首页 > 移动开发 > IOS开发

iOS 开启个人热点后屏幕的适配问题

2016-02-25 11:20 507 查看
//iOS 在开启个人热点后会调用此方法
- (void)viewWillLayoutSubviews
//
// ViewController.m
// test_Person_Hotspot_01
//
// Created by admin on 1/28/16.
// Copyright © 2016 jeffasd. All rights reserved.
//

#import "ViewController.h"

#define SCREEN_WIDTH [[UIScreen mainScreen] bounds].size.width/2

#define SCREEN_HEIGHT [[UIScreen mainScreen] bounds].size.height

@interface ViewController ()
{
UIButton *button;
}

@end

@implementation ViewController

- (void)viewDidLoad {
[super
viewDidLoad];

button = [UIButton
buttonWithType:UIButtonTypeCustom];

// [[UIScreen mainScreen] bounds].size.width/2;

// button.frame = CGRectMake(SCREEN_WIDTH, SCREEN_HEIGHT - 20 -50, 50, 50);

button.frame =
CGRectMake(SCREEN_WIDTH,
self.view.frame.size.height
- 20 -50,
50, 50);

// button.bounds = CGRectMake(SCREEN_WIDTH, SCREEN_HEIGHT - 20 -50, 50, 50);

// button.bounds = CGRectMake(50, 50, 50, 42);

button.backgroundColor = [UIColor
cyanColor];

[self.view
addSubview:button];

self.tabBar.frame =
CGRectMake(0,
self.view.frame.size.height-40,
320, 40);

}

- (void)viewWillAppear:(BOOL)animated{
[super
viewWillAppear:animated];

self.view.backgroundColor = [UIColor
whiteColor];
}

- (void)viewDidAppear:(BOOL)animated{
[super
viewDidAppear:animated];

self.view.backgroundColor = [UIColor
whiteColor];
}

- (void)viewWillDisappear:(BOOL)animated{
[super
viewWillDisappear:animated];

self.view.backgroundColor = [UIColor
whiteColor];
}

//iOS 在开启个人热点后会调用此方法
- (void)viewWillLayoutSubviews{

button.frame =
CGRectMake(SCREEN_WIDTH,
self.view.frame.size.height
- 20 -50,
50, 50);

[super
viewWillLayoutSubviews];

self.view.backgroundColor = [UIColor
redColor];

[self.view
layoutSubviews];

NSLog(@"the Screen is %@",
NSStringFromCGRect([[UIScreen
mainScreen] bounds]));

NSLog(@"the VC view frame is %@",
NSStringFromCGRect(self.view.frame));

// button.frame = CGRectMake(SCREEN_WIDTH, SCREEN_HEIGHT - 20 -50, 50, 50);

// button.frame = CGRectMake(SCREEN_WIDTH, self.view.frame.size.height - 20 -50, 50, 50);
}

- (void)didReceiveMemoryWarning {
[super
didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: