Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes scrollView.contentSize resizing #21

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 42 additions & 9 deletions VENTokenField/VENTokenField.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,32 @@ - (void)awakeFromNib
[self setUpInit];
}

#pragma mark - UIResponder

- (BOOL)canBecomeFirstResponder
{
return [self.inputTextField canBecomeFirstResponder];
}

- (BOOL)becomeFirstResponder
{
[self reloadData];
[self inputTextFieldBecomeFirstResponder];
return YES;
}

- (BOOL)canResignFirstResponder
{
return [self.inputTextField canResignFirstResponder];
}

- (BOOL)resignFirstResponder
{
return [self.inputTextField resignFirstResponder];
}

#pragma mark - Setup

- (void)setUpInit
{
// Set up default values.
Expand Down Expand Up @@ -127,15 +141,7 @@ - (void)reloadData

self.tokens = [NSMutableArray array];

CGFloat currentX = 0;
CGFloat currentY = 0;

[self layoutToLabelInView:self.scrollView origin:CGPointZero currentX:&currentX];
[self layoutTokensWithCurrentX:&currentX currentY:&currentY];
[self layoutInputTextFieldWithCurrentX:&currentX currentY:&currentY];

[self adjustHeightForCurrentY:currentY];
[self.scrollView setContentSize:CGSizeMake(self.scrollView.contentSize.width, currentY + [self heightForToken])];
[self commitLayoutSubviews];

[self updateInputTextField];

Expand Down Expand Up @@ -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:&currentX];
[self layoutTokensWithCurrentX:&currentX currentY:&currentY];
[self layoutInputTextFieldWithCurrentX:&currentX currentY:&currentY];

[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))];
Expand Down