国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 淮南市| 宽甸| 南开区| 宿松县| 册亨县| 曲阳县| 景谷| 含山县| 普洱| 威海市| 盐池县| 乌苏市| 军事| 百色市| 上杭县| 云龙县| 平乡县| 绥德县| 漳浦县| 宁安市| 大关县| 太康县| 望江县| 牟定县| 德化县| 灵宝市| 东城区| 东台市| 凭祥市| 江山市| 谷城县| 锦屏县| 平果县| 太康县| 阜新市| 呼图壁县| 尼木县| 衢州市| 顺昌县| 罗山县| 永善县|