Skip to content

Instantly share code, notes, and snippets.

@tomohisa
Created December 30, 2014 14:12
Show Gist options
  • Save tomohisa/57c7009a8b0f89e852b6 to your computer and use it in GitHub Desktop.
Save tomohisa/57c7009a8b0f89e852b6 to your computer and use it in GitHub Desktop.
Setting Keyboard Hight same even in Enlarged App
- (void)viewDidLoad {
[super viewDidLoad];
self.view.translatesAutoresizingMaskIntoConstraints = NO;
if (self.traitCollection.userInterfaceIdiom == UIUserInterfaceIdiomPad) {
self.portraitHeightRate = [UIScreen mainScreen].bounds.size.width * .4 / [UIScreen mainScreen].bounds.size.height;
}else{
if (([UIScreen mainScreen].bounds.size.width + [UIScreen mainScreen].bounds.size.height)>1100) {
self.portraitHeightRate = [UIScreen mainScreen].bounds.size.width * .6 / [UIScreen mainScreen].bounds.size.height;
} else if (([UIScreen mainScreen].bounds.size.width + [UIScreen mainScreen].bounds.size.height)>950) {
self.portraitHeightRate = [UIScreen mainScreen].bounds.size.width * .75 / [UIScreen mainScreen].bounds.size.height;
} else {
self.portraitHeightRate = [UIScreen mainScreen].bounds.size.width * .85 / [UIScreen mainScreen].bounds.size.height;
}
}
if (self.landscapeHeightRate ==0) {
if (self.traitCollection.userInterfaceIdiom == UIUserInterfaceIdiomPad) {
self.landscapeHeightRate = [UIScreen mainScreen].bounds.size.width * .45 / [UIScreen mainScreen].bounds.size.height;
}else{
self.landscapeHeightRate = .5;
}
}
}
- (CGFloat) calcuratedHeight {
if (self.traitCollection.userInterfaceIdiom == UIUserInterfaceIdiomPhone) {
if([self isPortrait]){
return ((int) (self.portraitHeightRate * [UIScreen mainScreen].bounds.size.height * self.view.bounds.size.width / [UIScreen mainScreen].bounds.size.width / 10.0))*10;
}else{
return ((int) (self.landscapeHeightRate * [UIScreen mainScreen].bounds.size.height * self.view.bounds.size.width / [UIScreen mainScreen].bounds.size.width / 10.0))*10;
}
}
if (self.traitCollection.userInterfaceIdiom == UIUserInterfaceIdiomPad) {
if([self isPortrait]){
return ((int) (self.portraitHeightRate * [UIScreen mainScreen].bounds.size.height * self.view.bounds.size.width / [UIScreen mainScreen].bounds.size.width / 10.0))*10;
}else{
return ((int) (self.landscapeHeightRate * [UIScreen mainScreen].bounds.size.height * self.view.bounds.size.width / [UIScreen mainScreen].bounds.size.width / 10.0))*10;
}
}
return 200;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment