可以根据自己的需要稍加修改,属性丰富易查。
.h文件
#import <UIKit/UIKit.h>
typedef enum HMPopUpType{
HMAlertView,
HMInputView
}HMPopUpType;
typedef NS_ENUM(NSInteger, HMPopUpTransitionType) {
HMPopUpTransitionTypePop,
HMPopUpTransitionTypePopFromBottom,
HMPopUpTransitionTypePopFromTop,
HMPopUpTransitionTypeFadeIn,
HMPopUpTransitionTypeFadeInFromBottom,
HMPopUpTransitionTypeFadeInFromTop
};
typedef NS_ENUM(NSInteger, HMPopUpDismissType) {
HMPopUpDismissTypeFadeOut,
HMPopUpDismissTypeFadeOutBottom,
HMPopUpDismissTypeFadeOutTop
};
#pragma mark - Delegate
/**
* HMPopUpViewDelegate Protocol
*/
@class HMPopUpView;
@protocol HMPopUpViewDelegate <NSObject>
@optional
/**
* Delegate method to detect user event whether accept or not
*
* @param alert HMPopUpView
* @param accept YES or NO
*/
- (void) popUpView:(HMPopUpView *)view accepted:(BOOL)accept inputText:(NSString *)text;
@end
@interface HMPopUpView : UIView <UITextFieldDelegate>
#pragma mark - Properties
/**
* HMPopUpViewDelegate delegate propoerty
*/
@property (nonatomic, strong) id<HMPopUpViewDelegate> hmDelegate;
/**
* Sets the font for the title.
*/
@property (nonatomic, strong) UIFont * titleFont;
/**
* Sets the font for the text field.
*/
@property (nonatomic, strong) UIFont * textFieldFont;
/**
* Sets the border color around the pop up view.
*/
@property (nonatomic, strong) UIColor * borderColor;
/**
* Sets the background color for the separator view between the title label and text field.
*/
@property (nonatomic, strong) UIColor * titleSeparatorColor;
/**
* Sets the background color for button view.
*/
@property (nonatomic, strong) UIColor * buttonViewBGColor;
/**
* sets the background color for the text field.
*/
@property (nonatomic, strong) UIColor * textFieldBGColor;
/**
* sets the boarder width for the text field.
*/
@property (nonatomic, assign) CGFloat textFieldBoarderWidth;
/**
* sets the boarder color for the text field.
*/
@property (nonatomic, strong) UIColor * textFieldBoarderColor;
/**
* sets the background color for the middle view which the text field is positioned area.
*/
@property (nonatomic, strong) UIColor * middleViewBGColor;
/**
* Sets the transition type. Default is HMPopUpTransitionTypePop
*/
@property (nonatomic, assign) HMPopUpTransitionType transitionType;
/**
* Sets the transition type. Default is HMPopUpDismissTypeFadeOut
*/
@property (nonatomic, assign) HMPopUpDismissType dismissType;
/**
* Sets the presentation animation duration. Default is 0.8
*/
@property (nonatomic, assign) NSTimeInterval presentAnimationDuration;
/**
* Sets the dismiss animation duration. Default is 0.4
*/
@property (nonatomic, assign) NSTimeInterval dismissAnimationDuration;
/**
* Sets the text color of the text field. Default is White.
*/
@property (nonatomic, strong) UIColor * textFieldTextColor;
@property (nonatomic, strong) UIColor * okButtonTextColor;
/**
* Sets the 'Ok' button background color
*/
@property (nonatomic, strong) UIColor * okButtonBGColor;
@property (nonatomic, strong) UIColor * cancelButtonTextColor;
/**
*set TextField
*/
@property (nonatomic, strong) UITextField * name;
@property (nonatomic, strong) UITextField * imageName;
@property (nonatomic, strong) UITextField * modelName;
@property (nonatomic, strong) UITextField * descript;
@property (nonatomic, strong) UILabel * des;
/**
*set Title Color
*/
@property (nonatomic, strong) UIColor * titleBGColor;
/**
* Sets the 'Cancel' button background color
*/
@property (nonatomic, strong) UIColor * cancelButtonBGColor;
/**
* Sets the border width for the pop up view. Default is 2.
*/
@property (nonatomic, assign) float borderWidth;
#pragma mark - Methods
/**
* Intializing view with View Title, Button titles (ok/cancel), HMPopUpViewDelegate.
*
* @param title title for view
* @param okBtnTtl title for ok button
* @param cnclBtnTtl title for cancel button
* @param delegate HMPopUpViewDelegate to enable delegate mothods
*
* @return id
*/
- (id)initWithTitle:(NSString *)title
okButtonTitle:(NSString *)okBtnTtl
cancelButtonTitle:(NSString *)cnclBtnTtl
delegate:(id<HMPopUpViewDelegate>)delegate;
/**
* User is allowed to configure the view with colors.
*
* @param BGColor alert view background color
* @param ttlColor title label color (text color)
* @param btnBGColor background color for buttons ("ok" or "cancel")
* @param btnTxtColor button title label color (text color)
*/
- (void)configureHMPopUpViewWithBGColor:(UIColor *)BGColor
titleColor:(UIColor *)ttlColor
buttonViewColor:(UIColor *)btnViewColor
buttonBGColor:(UIColor *)btnBGColor
buttonTextColor:(UIColor *)btnTxtColor;
/**
* Adding HMPopUpView to current ViewController's view
*
* @param view current ViewController's view
*/
- (void)showInView:(UIView *)view;
@end
.m文件
#import "HMPopUpView.h"
#define DEFAULT_BORDER_WIDTH 2
#define DEFAULT_PRESENTATION_ANIMATION_DURATION 1
#define DEFAULT_DISMISS_ANIMATION_DURATION 0.8
@interface HMPopUpView ()<UITextViewDelegate>{
UIView *HUD, *containerView, *separatorView, *buttonView, *middleView;
UILabel *lblTitle, *lblMessage, *nameLbl, *descriptLbl, *imgLbl, *modelLbl;
UIButton *btnOk, *btnCancel;
NSTimeInterval presentDuration, dismissDuration;
}
@end
@implementation HMPopUpView
@synthesize hmDelegate = _hmDelegate, transitionType, dismissType;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
-(id)initWithTitle:(NSString *)title okButtonTitle:(NSString *)okBtnTtl cancelButtonTitle:(NSString *)cnclBtnTtl delegate:(id<HMPopUpViewDelegate>)delegate {
self = [super initWithFrame:[[UIScreen mainScreen] bounds]];
if (self) {
_hmDelegate = delegate;
self.backgroundColor = [UIColor clearColor];
HUD = [[UIView alloc] initWithFrame:self.bounds];
HUD.backgroundColor = [UIColor whiteColor];
HUD.alpha = .7;
[self addSubview:HUD];
//Creating the view which contains all UI components
containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 280, 300)];
containerView.backgroundColor = [UIColor blackColor];
containerView.layer.cornerRadius = 5;
containerView.clipsToBounds = YES;
CGRect cnvwFrame = containerView.bounds;
cnvwFrame.origin.x = self.frame.size.width / 2 - (cnvwFrame.size.width / 2);
cnvwFrame.origin.y = self.frame.size.height / 2 - (cnvwFrame.size.height / 2);
containerView.frame = cnvwFrame;
[self addSubview:containerView];
CGRect cvFrame = containerView.bounds;
//Separator View creation
separatorView = [[UIView alloc] initWithFrame:CGRectMake(cvFrame.origin.x, cvFrame.origin.y + 45, cvFrame.size.width, 1)];
separatorView.backgroundColor = [UIColor whiteColor];
[containerView addSubview:separatorView];
//Title label
lblTitle = [[UILabel alloc] initWithFrame:CGRectMake(cvFrame.origin.x + 20, cvFrame.origin.y + 15, cvFrame.size.width - 40, 22)];
lblTitle.numberOfLines = 1;
lblTitle.text = title;
lblTitle.textColor = [UIColor whiteColor];
lblTitle.textAlignment = NSTextAlignmentCenter;
lblTitle.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:15];
[containerView addSubview:lblTitle];
//TextField for user inputs
nameLbl=[[UILabel alloc]initWithFrame:CGRectMake(5,cvFrame.origin.y+70,50, 30)];
nameLbl.font=[UIFont systemFontOfSize:15];
nameLbl.text = @"名称:";
nameLbl.adjustsFontSizeToFitWidth = YES;
_name = [[UITextField alloc] initWithFrame:CGRectMake(cvFrame.origin.x + 60, cvFrame.origin.y + 70, cvFrame.size.width - 80, 30)];
_name.textAlignment = NSTextAlignmentCenter;
_name.tag = 1;
_name.backgroundColor = [UIColor colorWithRed:0.181 green:0.663 blue:0.882 alpha:0.500];
_name.layer.cornerRadius = 3;
_name.clipsToBounds = YES;
[_name setEnabled:YES];
_name.textColor = [UIColor blackColor];
_name.tintColor = [UIColor blackColor];
_name.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:15];
_name.delegate = self;
[containerView addSubview:_name];
[containerView addSubview:nameLbl];
imgLbl=[[UILabel alloc]initWithFrame:CGRectMake(5,cvFrame.origin.y+120,50, 30)];
imgLbl.font=[UIFont systemFontOfSize:15];
imgLbl.text = @"图片:";
imgLbl.adjustsFontSizeToFitWidth = YES;
_imageName = [[UITextField alloc]initWithFrame:CGRectMake(cvFrame.origin.x+60, cvFrame.origin.y +120, cvFrame.size.width-80, 30)];
_imageName.textAlignment= NSTextAlignmentCenter;
_imageName.tag = 2;
_imageName.backgroundColor = [UIColor colorWithRed:0.181 green:0.663 blue:0.882 alpha:0.500];
_imageName.layer.cornerRadius = 3;
_imageName.clipsToBounds = YES;
[_imageName setEnabled:NO];
_imageName.textColor = [UIColor blackColor];
_imageName.tintColor = [UIColor blackColor];
_imageName.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:15];
_imageName.delegate = self;
[containerView addSubview:_imageName];
[containerView addSubview:imgLbl];
modelLbl=[[UILabel alloc]initWithFrame:CGRectMake(5,cvFrame.origin.y+170,50, 30)];
modelLbl.font=[UIFont systemFontOfSize:15];
modelLbl.text = @"模型:";
modelLbl.adjustsFontSizeToFitWidth = YES;
_modelName = [[UITextField alloc]initWithFrame:CGRectMake(cvFrame.origin.x+60, cvFrame.origin.y +170, cvFrame.size.width-80, 30)];
_modelName.textAlignment= NSTextAlignmentCenter;
_modelName.tag = 3;
_modelName.backgroundColor = [UIColor colorWithRed:0.181 green:0.663 blue:0.882 alpha:0.500];
_modelName.layer.cornerRadius = 3;
_modelName.clipsToBounds = YES;
[_modelName setEnabled:NO];
_modelName.textColor = [UIColor blackColor];
_modelName.tintColor = [UIColor blackColor];
_modelName.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:15];
_modelName.delegate = self;
[containerView addSubview:_modelName];
[containerView addSubview:modelLbl];
descriptLbl=[[UILabel alloc]initWithFrame:CGRectMake(5,cvFrame.origin.y+220,50, 30)];
descriptLbl.font=[UIFont systemFontOfSize:15];
descriptLbl.text = @"描述:";
descriptLbl.adjustsFontSizeToFitWidth = YES;
_descript = [[UITextField alloc] initWithFrame:CGRectMake(cvFrame.origin.x + 60, cvFrame.origin.y + 220, cvFrame.size.width - 80, 30)];
_descript.textAlignment = NSTextAlignmentCenter;
_descript.backgroundColor = [UIColor colorWithRed:0.181 green:0.663 blue:0.882 alpha:0.500];
_descript.layer.cornerRadius = 3;
_descript.tag = 4;
_descript.clipsToBounds = YES;
[_descript setEnabled:YES];
_descript.textColor = [UIColor blackColor];
_descript.tintColor = [UIColor blackColor];
_descript.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:15];
_descript.delegate = self;
[containerView addSubview:_descript];
[containerView addSubview:descriptLbl];
//Button view creation
buttonView = [[UIView alloc] initWithFrame:CGRectMake(cvFrame.origin.x , cvFrame.origin.y + 258, cvFrame.size.width, cvFrame.size.height - 130)];
buttonView.backgroundColor = [UIColor whiteColor];
[containerView addSubview:buttonView];
//Action button creation
btnOk = [[UIButton alloc] initWithFrame:CGRectMake(cvFrame.origin.x , cvFrame.origin.y + 260, cvFrame.size.width / 2 - 1, 39)];
[btnOk setTitle:okBtnTtl forState:UIControlStateNormal];
btnOk.backgroundColor = [UIColor blackColor];
btnOk.titleLabel.textColor = [UIColor whiteColor];
btnOk.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:15];
[containerView addSubview:btnOk];
[btnOk addTarget:self action:@selector(acceptAction) forControlEvents:UIControlEventTouchUpInside];
btnCancel = [[UIButton alloc] initWithFrame:CGRectMake(btnOk.frame.origin.x + btnOk.frame.size.width + 1, cvFrame.origin.y + 260, cvFrame.size.width / 2, 39)];
[btnCancel setTitle:cnclBtnTtl forState:UIControlStateNormal];
btnCancel.backgroundColor = [UIColor blackColor];
btnCancel.titleLabel.textColor = [UIColor whiteColor];
btnCancel.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:15];
[containerView addSubview:btnCancel];
[btnCancel addTarget:self action:@selector(cancelAction) forControlEvents:UIControlEventTouchUpInside];
middleView = [[UIView alloc] initWithFrame:CGRectMake(cvFrame.origin.x, separatorView.frame.origin.y + separatorView.frame.size.height, cvFrame.size.width, btnOk.frame.origin.y)];
middleView.backgroundColor = [UIColor whiteColor];
[containerView insertSubview:middleView belowSubview:_name];
// [containerView insertSubview:middleView belowSubview:_descript];
presentDuration = DEFAULT_PRESENTATION_ANIMATION_DURATION;
dismissDuration = DEFAULT_DISMISS_ANIMATION_DURATION;
}
return self;
}
-(void)configureHMPopUpViewWithBGColor:(UIColor *)BGColor titleColor:(UIColor *)ttlColor buttonViewColor:(UIColor *)btnViewColor buttonBGColor:(UIColor *)btnBGColor buttonTextColor:(UIColor *)btnTxtColor {
containerView.backgroundColor = BGColor;
lblTitle.textColor = ttlColor;
buttonView.backgroundColor = btnViewColor;
btnOk.backgroundColor = btnBGColor;
btnCancel.backgroundColor = btnBGColor;
// btnOk.titleLabel.textColor = btnTxtColor;
// btnCancel.titleLabel.textColor = btnTxtColor;
[btnOk setTitleColor:btnTxtColor forState:UIControlStateNormal | UIControlStateHighlighted | UIControlStateSelected];
[btnCancel setTitleColor:btnTxtColor forState:UIControlStateNormal | UIControlStateHighlighted | UIControlStateSelected];
btnCancel.titleLabel.textColor = [UIColor colorWithRed:0.181 green:0.663 blue:0.882 alpha:1.000];
// [btnOk.titleLabel setTextColor:btnTxtColor];
}
-(void)setMiddleViewBGColor:(UIColor *)middleViewBGColor {
middleView.backgroundColor = middleViewBGColor;
}
-(void)setTextFieldFont:(UIFont *)textFieldFont {
_name.font = textFieldFont;
_descript.font = textFieldFont;
}
-(void)setTitleFont:(UIFont *)titleFont {
lblTitle.font = titleFont;
}
-(void)setBorderColor:(UIColor *)borderColor {
containerView.layer.borderWidth = DEFAULT_BORDER_WIDTH;
containerView.layer.borderColor = borderColor.CGColor;
}
-(void)setTitleSeparatorColor:(UIColor *)titleSeparatorColor {
separatorView.backgroundColor = titleSeparatorColor;
}
-(void)setButtonViewBGColor:(UIColor *)buttonViewBGColor {
buttonView.backgroundColor = buttonViewBGColor;
}
-(void)setTextFieldBGColor:(UIColor *)textFieldBGColor {
_name.backgroundColor = textFieldBGColor;
_descript.backgroundColor = textFieldBGColor;
}
-(void)setTextFieldTextColor:(UIColor *)textFieldTextColor {
_name.textColor = textFieldTextColor;
_descript.textColor = textFieldTextColor;
}
-(void)setTextFieldBoarderWidth:(CGFloat)textFieldBoarderWidth {
_name.layer.borderWidth = textFieldBoarderWidth;
_descript.layer.borderWidth = textFieldBoarderWidth;
}
-(void)setTextFieldBoarderColor:(UIColor *)textFieldBoarderColor {
_name.layer.borderColor = textFieldBoarderColor.CGColor;
_descript.layer.borderColor = textFieldBoarderColor.CGColor;
}
-(void)setBorderWidth:(float)borderWidth {
containerView.layer.borderWidth = borderWidth;
}
-(void)setOkButtonTextColor:(UIColor *)okButtonTextColor{
btnOk.titleLabel.textColor = okButtonTextColor;
}
-(void)setTitleBGColor:(UIColor *)titleColor{
containerView.backgroundColor=titleColor;
}
-(void)setOkButtonBGColor:(UIColor *)okButtonBGColor{
btnOk.backgroundColor = okButtonBGColor;
}
-(void)setCancelButtonBGColor:(UIColor *)cancelButtonBGColor{
btnCancel.backgroundColor=cancelButtonBGColor;
}
-(void)setPresentAnimationDuration:(NSTimeInterval)presentAnimationDuration{
presentDuration = presentAnimationDuration;
}
-(void)setDismissAnimationDuration:(NSTimeInterval)dismissAnimationDuration {
dismissDuration = dismissAnimationDuration;
}
#pragma mark - PopUpView Button Actions
- (void)acceptAction {
[self hide];
if ([_hmDelegate respondsToSelector:@selector(popUpView:accepted:inputText:)]) {
[_hmDelegate popUpView:self accepted:YES inputText:_name.text];
[_hmDelegate popUpView:self accepted:YES inputText:_descript.text];
}
}
- (void)cancelAction {
[self hide];
if ([_hmDelegate respondsToSelector:@selector(popUpView:accepted:inputText:)]) {
[_hmDelegate popUpView:self accepted:NO inputText:_name.text];
[_hmDelegate popUpView:self accepted:NO inputText:_descript.text];
}
}
#pragma mark - PopUpView
- (void)showInView:(UIView *)view {
containerView.alpha = 0;
[view addSubview:self];
switch (transitionType) {
case HMPopUpTransitionTypePop: {
containerView.transform = CGAffineTransformMakeScale(0, 0);
[UIView animateWithDuration:presentDuration
delay:0
usingSpringWithDamping:0.7
initialSpringVelocity:1
options:UIViewAnimationOptionAllowUserInteraction
animations:^{
containerView.alpha = 1.0f;
containerView.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) {
}];
break;
}
case HMPopUpTransitionTypePopFromBottom: {
// containerView.transform = CGAffineTransformMakeScale(0.0, 0.0);
// containerView.transform = CGAffineTransformMakeTranslation(0, [UIScreen mainScreen].bounds.size.height - 200);
CGAffineTransform t1 = CGAffineTransformMakeScale(0.0, 0.0);
CGAffineTransform t2 = CGAffineTransformMakeTranslation(0, [UIScreen mainScreen].bounds.size.height );
containerView.transform = CGAffineTransformConcat(t1, t2);
[UIView animateWithDuration:presentDuration
delay:0
usingSpringWithDamping:0.7
initialSpringVelocity:1
options:UIViewAnimationOptionAllowUserInteraction
animations:^{
containerView.alpha = 1.0f;
containerView.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) {
}];
break;
}
case HMPopUpTransitionTypePopFromTop: {
CGAffineTransform t1 = CGAffineTransformMakeScale(0.0, 0.0);
CGAffineTransform t2 = CGAffineTransformMakeTranslation(0, [UIScreen mainScreen].bounds.origin.y - containerView.frame.size.height*2);
containerView.transform = CGAffineTransformConcat(t1, t2);
[UIView animateWithDuration:presentDuration
delay:0
usingSpringWithDamping:0.7
initialSpringVelocity:1
options:UIViewAnimationOptionAllowUserInteraction
animations:^{
containerView.alpha = 1.0f;
containerView.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) {
}];
break;
}
case HMPopUpTransitionTypeFadeIn: {
[UIView animateWithDuration:presentDuration animations:^{
containerView.alpha = 1.0f;
}];
break;
}
case HMPopUpTransitionTypeFadeInFromBottom: {
containerView.transform = CGAffineTransformMakeTranslation(0, [UIScreen mainScreen].bounds.size.height - 200);
[UIView animateWithDuration:presentDuration
delay:0
usingSpringWithDamping:1
initialSpringVelocity:1
options:UIViewAnimationOptionCurveEaseIn
animations:^{
containerView.alpha = 1.0f;
containerView.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) {
}];
break;
}
case HMPopUpTransitionTypeFadeInFromTop: {
containerView.transform = CGAffineTransformMakeTranslation(0, [UIScreen mainScreen].bounds.origin.y - 200);
[UIView animateWithDuration:presentDuration
delay:0
usingSpringWithDamping:1
initialSpringVelocity:1
options:UIViewAnimationOptionCurveEaseIn
animations:^{
containerView.alpha = 1.0f;
containerView.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) {
}];
break;
}
default: {
containerView.transform = CGAffineTransformMakeScale(0, 0);
[UIView animateWithDuration:presentDuration
delay:0
usingSpringWithDamping:0.7
initialSpringVelocity:1
options:UIViewAnimationOptionAllowUserInteraction
animations:^{
containerView.alpha = 1.0f;
containerView.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) {
}];
break;
}
}
}
- (void)hide {
if ([_name isEditing]) {
[_name resignFirstResponder];
}
if ([_descript isEditing]) {
[_descript resignFirstResponder];
}
switch (dismissType) {
case HMPopUpDismissTypeFadeOut: {
[UIView animateWithDuration:dismissDuration
delay:0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
containerView.alpha = 0.0;
self.alpha = 0.0;
}
completion:^(BOOL finished) {
[self removeFromSuperview];
}];
break;
}
case HMPopUpDismissTypeFadeOutBottom: {
[UIView animateWithDuration:dismissDuration
delay:0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
containerView.alpha = 0;
self.alpha = 0.0;
containerView.transform = CGAffineTransformMakeTranslation(0, [UIScreen mainScreen].bounds.size.height);
} completion:^(BOOL finished) {
}];
break;
}
case HMPopUpDismissTypeFadeOutTop: {
[UIView animateWithDuration:dismissDuration
delay:0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
containerView.alpha = 0;
self.alpha = 0.0;
containerView.transform = CGAffineTransformMakeTranslation(0, -(containerView.frame.size.height+containerView.frame.origin.y));
} completion:^(BOOL finished) {
}];
break;
}
default: {
[UIView animateWithDuration:dismissDuration
delay:0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
containerView.alpha = 0.0;
self.alpha = 0.0;
}
completion:^(BOOL finished) {
[self removeFromSuperview];
}];
break;
}
}
}
#pragma mark - TextField Delegate
-(void)textFieldDidBeginEditing:(UITextField *)textField {
if (textField == _name) {
if ([UIScreen mainScreen].bounds.size.height < 570) {
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
containerView.transform = CGAffineTransformMakeTranslation(0, -70);
} completion:^(BOOL finished) {
}];
}
}
if (textField == _descript) {
if ([UIScreen mainScreen].bounds.size.height < 570) {
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
containerView.transform = CGAffineTransformMakeTranslation(0, -70);
} completion:^(BOOL finished) {
}];
}
}
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
if (textField == _name) {
[_name resignFirstResponder];
if ([UIScreen mainScreen].bounds.size.height < 570) {
if (containerView.frame.origin.y < self.frame.size.height / 2 - (containerView.frame.size.height / 2)) {
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
containerView.transform = CGAffineTransformMakeTranslation(0, 0);
} completion:^(BOOL finished) {
}];
}
}
}
if (textField == _descript) {
[_name resignFirstResponder];
if ([UIScreen mainScreen].bounds.size.height < 570) {
if (containerView.frame.origin.y < self.frame.size.height / 2 - (containerView.frame.size.height / 2)) {
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
containerView.transform = CGAffineTransformMakeTranslation(0, 0);
} completion:^(BOOL finished) {
}];
}
}
}
return YES;
}
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
NSString *newText = [textField.text stringByReplacingCharactersInRange:range withString:string];
if (textField == _name && newText.length > 0) {
btnOk.enabled = YES;
btnOk.alpha = 1;
}
else if (textField == _name && newText.length > 0) {
btnOk.enabled = YES;
btnOk.alpha = 1;
}else {
btnOk.enabled = NO;
btnOk.alpha = 0.5;
}
return YES;
}
@end