简体   繁体   中英

How to adjust Scrollview content size using autolayouts

Hi in my project i have added scrollview on viewcontroller and inside that scrollview i have added textfields and buttons

After that i have added auto-layouts for all fields as like below image there i have added bottom space container is "58"

but when i clicked on textfield i have changed scrollview content size like below and fine that's ok

- (void)textFieldDidBeginEditing:(UITextField *)textField;
{
   [self.mainscrollview setContentSize:CGSizeMake(100, 700)];

}

here my main intention is when i clicked keyboard return button i want to set scroll view content size as like previous what i have applied

for this i have written some code but this showing exceptions please help me

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *bottomSpaceContraint;

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self.mainscrollview setContentSize:(100, bottomContraint.size.height)];
    return YES;
}

在此处输入图片说明

Your question is not really clear, but if you want to adjust the scroll view based on the presence of the keyboard use the awesome framework TPKeyboardAvoiding . Also, you have tagged your question with swift, but the code you provided is objc. You might wanna change the tag.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM