diff --git a/VENTokenField/VENTokenField.m b/VENTokenField/VENTokenField.m index e51040a..282333e 100644 --- a/VENTokenField/VENTokenField.m +++ b/VENTokenField/VENTokenField.m @@ -64,6 +64,13 @@ - (void)awakeFromNib [self setUpInit]; } +#pragma mark - UIResponder + +- (BOOL)canBecomeFirstResponder +{ + return [self.inputTextField canBecomeFirstResponder]; +} + - (BOOL)becomeFirstResponder { [self reloadData]; @@ -71,11 +78,18 @@ - (BOOL)becomeFirstResponder return YES; } +- (BOOL)canResignFirstResponder +{ + return [self.inputTextField canResignFirstResponder]; +} + - (BOOL)resignFirstResponder { return [self.inputTextField resignFirstResponder]; } +#pragma mark - Setup + - (void)setUpInit { // Set up default values. @@ -127,15 +141,7 @@ - (void)reloadData self.tokens = [NSMutableArray array]; - CGFloat currentX = 0; - CGFloat currentY = 0; - - [self layoutToLabelInView:self.scrollView origin:CGPointZero currentX:¤tX]; - [self layoutTokensWithCurrentX:¤tX currentY:¤tY]; - [self layoutInputTextFieldWithCurrentX:¤tX currentY:¤tY]; - - [self adjustHeightForCurrentY:currentY]; - [self.scrollView setContentSize:CGSizeMake(self.scrollView.contentSize.width, currentY + [self heightForToken])]; + [self commitLayoutSubviews]; [self updateInputTextField]; @@ -187,6 +193,33 @@ - (NSString *)inputText #pragma mark - View Layout +- (void)layoutSubviews +{ + [super layoutSubviews]; + + [self commitLayoutSubviews]; +} + +- (void)commitLayoutSubviews +{ + + self.scrollView.contentSize = CGSizeMake(CGRectGetWidth(self.frame) - self.horizontalInset * 2, CGRectGetHeight(self.frame) - self.verticalInset * 2); + self.scrollView.contentInset = UIEdgeInsetsMake(self.verticalInset, + self.horizontalInset, + self.verticalInset, + self.horizontalInset); + + CGFloat currentX = 0; + CGFloat currentY = 0; + + [self layoutToLabelInView:self.scrollView origin:CGPointZero currentX:¤tX]; + [self layoutTokensWithCurrentX:¤tX currentY:¤tY]; + [self layoutInputTextFieldWithCurrentX:¤tX currentY:¤tY]; + + [self adjustHeightForCurrentY:currentY]; + [self.scrollView setContentSize:CGSizeMake(self.scrollView.contentSize.width, currentY + [self heightForToken])]; +} + - (void)layoutScrollView { self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.frame), CGRectGetHeight(self.frame))];