Last active
August 29, 2015 14:08
-
-
Save Sunnyztj/bffc6a05da37fba2b457 to your computer and use it in GitHub Desktop.
TextView or TextField animation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma mark - UITextViewDelegate | |
- (void)textViewDidBeginEditing:(UITextView *)textView { | |
self.isTextViewEdit = YES; | |
_currentTextView = textView; | |
CGFloat distance; | |
distance = (self.firstURLDescriptionTextView == textView ? 70 : 180); | |
if (IS_IPHONE_6_PLUS) { | |
distance += 35.0; | |
} | |
else if (IS_IPHONE_4) { | |
distance += IS_IOS_7 ? 75.0 : 110.0; | |
} | |
else if (IS_IPHONE_5) { | |
distance += IS_IOS_7 ? 5.0 : 28.0; | |
} | |
else if (IS_IPHONE_6) { | |
distance -= 10.0; | |
} | |
[self setupUIViewAnimations:distance]; | |
} | |
- (void)resetUIViewAnimations { | |
[self setupUIViewAnimations:0]; | |
} | |
- (void)textViewDidEndEditing:(UITextView *)textView { | |
self.isTextViewEdit = NO; | |
[self resetUIViewAnimations]; | |
} | |
- (void)setupUIViewAnimations:(CGFloat)moveDistance { | |
[UIView animateWithDuration:0.3 | |
animations:^{ | |
self.view.frame = CGRectMake(self.view.frame.origin.x, | |
-moveDistance, | |
self.view.frame.size.width, | |
self.view.frame.size.height); | |
} | |
completion:nil]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment