国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > iOS > 正文

iOS鍵盤自適應(yīng)彈出效果

2019-10-21 18:45:42
字體:
供稿:網(wǎng)友

一、iOS鍵盤自適應(yīng)彈出效果圖

iOS鍵盤自適應(yīng)彈出,iOS鍵盤彈出,iOS自適應(yīng)彈出

二、工程圖

iOS鍵盤自適應(yīng)彈出,iOS鍵盤彈出,iOS自適應(yīng)彈出

三、代碼

ViewController.h

#import <UIKit/UIKit.h>@interface ViewController : UIViewController<UITextFieldDelegate>@end

ViewController.m

#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad {  [super viewDidLoad];  // Do any additional setup after loading the view, typically from a nib.      UITextField *field=[[UITextField alloc]initWithFrame:CGRectMake(100, 300, 50, 50)];  field.backgroundColor=[UIColor redColor];  field.delegate=self;  [self.view addSubview:field];        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];  }#pragma -mark -keyboard notificatin- (void)keyboardWillShow:(NSNotification *)notification {  NSDictionary *info = [notification userInfo];  // keyboardHeight 為鍵盤高度  CGSize keyboardSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;  [self animateViewWithKeyboardHeight:keyboardSize.height];}- (void)keyboardWillHide:(NSNotification *)notification {  [self animateViewWithKeyboardHeight:0.0];}- (void)animateViewWithKeyboardHeight:(CGFloat)keyboardHeight {  NSTimeInterval animationDuration = 0.3f;  CGFloat height = self.view.bounds.size.height;  CGFloat width = self.view.bounds.size.width;  CGFloat topSize = 0.0;  CGFloat viewH = self.view.frame.size.height-64;  CGFloat deviceHeight = [UIScreen mainScreen].bounds.size.height;  CGFloat animateH = deviceHeight - viewH - keyboardHeight;  if (animateH >= 0) {    topSize = 0;    CGRect toRect = CGRectMake(0, topSize, width, height);    self.view.frame = toRect;      } else {    topSize = animateH;    CGRect toRect = CGRectMake(0, topSize, width, height);    [UIView animateWithDuration:animationDuration animations:^{      self.view.frame = toRect;    }];  }}#pragma -mark -UITextFieldDelegate-(BOOL)textFieldShouldReturn:(UITextField *)textField{  [textField resignFirstResponder];    return YES;}- (void)didReceiveMemoryWarning {  [super didReceiveMemoryWarning];  // Dispose of any resources that can be recreated.}@end

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


注:相關(guān)教程知識(shí)閱讀請移步到IOS開發(fā)頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 阿巴嘎旗| 清远市| 雷山县| 山丹县| 陈巴尔虎旗| 隆林| 全南县| 密山市| 屏南县| 仙居县| 浮梁县| 纳雍县| 浦北县| 柘城县| 靖西县| 新田县| 五家渠市| 尖扎县| 南宁市| 靖州| 确山县| 延寿县| 西平县| 迭部县| 宝坻区| 沐川县| 巴塘县| 公安县| 梁平县| 蒙城县| 南部县| 霍林郭勒市| 故城县| 陆良县| 陕西省| 阜城县| 景谷| 红原县| 忻州市| 永登县| 社会|