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

首頁 > 系統 > iOS > 正文

iOS屏幕根據鍵盤自動變化高度

2020-07-26 02:45:56
字體:
來源:轉載
供稿:網友

一、效果圖

二、代碼

ViewController.h

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

ViewController.m

#import "ViewController.h"#define W [UIScreen mainScreen].bounds.size.width#define H [UIScreen mainScreen].bounds.size.height@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];}#pragma -mark -UITextFieldDelegate-(BOOL)textFieldShouldReturn:(UITextField *)textField{  [textField resignFirstResponder];    //self.view 恢復原位  NSTimeInterval animationDuration=0.10f;  [UIView beginAnimations:@"ResizeForKeyboard" context:nil];  [UIView setAnimationDuration:animationDuration];  float width = W;  float height = H;  float Y = 0.0f;  CGRect rect=CGRectMake(0.0f,Y,width,height);  self.view.frame=rect;  [UIView commitAnimations];    return YES;}-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{  NSTimeInterval animationDuration=0.30f;  [UIView beginAnimations:@"ResizeForKeyboard" context:nil];  [UIView setAnimationDuration:animationDuration];  float width = W;  float height = H;  //上移100個單位,按實際情況設置  CGRect rect=CGRectMake(0.0f,-100,width,height);  self.view.frame=rect;  [UIView commitAnimations];    return YES;}- (void)didReceiveMemoryWarning {  [super didReceiveMemoryWarning];  // Dispose of any resources that can be recreated.}@end

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宣恩县| 安溪县| 松阳县| 揭西县| 个旧市| 东山县| 彭山县| 汕尾市| 抚州市| 家居| 武隆县| 苏尼特右旗| 集贤县| 沙洋县| 平泉县| 建德市| 上虞市| 延庆县| 车险| 香港 | 聂拉木县| 芮城县| 唐海县| 蕲春县| 长泰县| 古浪县| 永福县| 安义县| 兴隆县| 玉林市| 富阳市| 色达县| 和龙市| 门源| 怀化市| 松潘县| 墨竹工卡县| 宁乡县| 蒙山县| 淮北市| 历史|