ios 鍵盤彈出視圖上移


@interface ImproveInformationVC ()<UITextFieldDelegate>//輸入框代理

@property (weak, nonatomic) IBOutlet RootTextField *userNameLabel;

@property (weak, nonatomic) IBOutlet RootTextField *contentLabel;

@property (weak, nonatomic) IBOutlet RootButton *nextBtn;

 

@property (weak, nonatomic) IBOutlet UIButton *maleBtn;

@property (weak, nonatomic) IBOutlet UIButton *femaleBtn;

@end

 

@implementation ImproveInformationVC

 

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    self.userNameLabel.delegate = self;//設置代理

    self.contentLabel.delegate = self;//設置代理

    [self initview];

}

 

 //開始編輯時 視圖上移 如果輸入框不被鍵盤遮擋則不上移。

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{

    CGFloat rects = self.view.frame.size.height - (textField.frame.origin.y + textField.frame.size.height + 216 +50);

    NSLog(@"aa%f",rects);

    if (rects <= 0) {

        [UIView animateWithDuration:0.3 animations:^{

            CGRect frame = self.view.frame;

            frame.origin.y = rects;

            self.view.frame = frame;

        }];

    }

   

    return YES;

}

//結束編輯時鍵盤下去 視圖下移動畫

-(BOOL)textFieldShouldEndEditing:(UITextField *)textField{

    [UIView animateWithDuration:0.3 animations:^{

        CGRect frame = self.view.frame;

        frame.origin.y = 0.0;

        self.view.frame = frame;

    }];

    

    return YES;

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM