Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // NSNotificationCenter の通知を利用
- // UIKeyboardDidChangeFrameNotification
- // キーボードのサイズが変更する時
- // キーボードが出るたびに毎回呼ばれる
- @implementation ViewController
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- // キーボードのサイズが変化するとき
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(keyboarDidChangeFrame:)
- name:UIKeyboardDidChangeFrameNotification
- object:nil];
- }
- - (void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- [[NSNotificationCenter defaultCenter] removeObserver:self
- name:UIKeyboardDidChangeFrameNotification
- object:nil];
- }
- // キーボードのサイズが変化するとき
- - (void)keyboarDidChangeFrame:(NSNotificationCenter*)notification
- {
- UIInterfaceOrientation orientation = self.interfaceOrientation;
- NSString *interfaceOrientation = [self getOrientation:orientation];
- NSLogE(@"現在の画面の向き: %@", interfaceOrientation);
- }
- - (NSString*)getOrientation:(UIInterfaceOrientation)interfaceOrientation
- {
- NSString *str;
- if(interfaceOrientation == UIInterfaceOrientationPortrait){
- str = @"portrait";
- } else if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft){
- str = @"landscape left";
- } else if(interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
- str = @"upsidedown";
- } else if(interfaceOrientation == UIInterfaceOrientationLandscapeRight){
- str = @"landscape right";
- }
- NSLogE(@"現在の画面の向き: %@", str);
- return str;
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement