iOS弹解盘时 控制界面滚动的封装类

来源:互联网 发布:写关于宿舍知乎 编辑:程序博客网 时间:2024/06/05 17:09

      大家都知道iOS不像安卓那样键盘弹出的时候输入框会往上边自动移动,很多时候回盖住输入框,带来不好的用户体验。所以我封装了一个类,专门用于弹出键盘时控制界面。代码如下,这两个类的代码我已经上传,在我上传的代码里可以找到。

#import <Foundation/Foundation.h>@interface SyAnimationUtil : NSObject/** *  点击UITextField需要弹起的View及高度 * *  @param formFrame Frame */+ (void)beginAnimationShowView:(UIView *)formView height:(float )height;/** *  点击UITextField需要隐藏的View及高度 * *  @param formFrame Frame */+ (void)beginAnimationHideView:(UIView *)formView height:(float )height;@end

#import "SyAnimationUtil.h"@implementation SyAnimationUtil+ (void)beginAnimationShowView:(UIView *)formView height:(float )height{    NSTimeInterval animationDuration = 0.30f;    CGRect frame = formView.frame;    frame.origin.y -=height;//    frame.size.height +=height;    [UIView beginAnimations:@"ResizeView" context:nil];    [UIView setAnimationDuration:animationDuration];    formView.frame = frame;    [UIView commitAnimations];}+ (void)beginAnimationHideView:(UIView *)formView height:(float )height{        NSTimeInterval animationDuration = 0.30f;    CGRect frame = formView.frame;    frame.origin.y +=height;//    frame.size.height -=height;    //self.view移回原位置    [UIView beginAnimations:@"ResizeView" context:nil];    [UIView setAnimationDuration:animationDuration];    formView.frame = frame;    [UIView commitAnimations];}@end


0 0
原创粉丝点击