UIActionSheet Changes UIScrollView Values

I came across what, in my opinion, might be a mistake, but I'm not quite sure. Therefore, I ask you in case you know about the fix.

I basically have UIScrollViewone that dynamically resizes based on the number UITextFields. It starts with one size (one text field), and then when more is added, the scroll content increases. It works great. However, when the user clicks the button that opens UIActionSheet, the content becomes 0. This makes scrolling non-programmable when he later rejects the action sheet. I put an instruction NSLogto check the contents of the scroll before and after the action sheet is presented, and it goes from any (e.g. 360) to 0.

However, this does not happen when I use UIAlertView. If there is no fix for this problem, alertview is my backup solution. However, I would prefer an action sheet, as it is better suited to the task.

I hope someone out there knows what can cause this and how I can fix it.

Thank!

As requested, here is some kind of relevant code:

Code to open the action sheet:

- (IBAction)addImage:(id)sender {
  UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Take a picture", @"Choose from photo album", nil];
  [actionSheet showInView:self.view];
}

Here's how I changed the scrollView value after adding a new text field:

CGFloat width = self.scrollView.bounds.size.width;
CGFloat height = CGRectGetMaxY(anotherTextField.frame);
self.scrollView.contentSize = CGSizeMake(width, height);

(Note what anotherTextField.framewill be the location of the new text box. So about 40 - 80 - 120 - 160, etc.)


Here viewDidLoad: (I don't have viewDidAppearor viewWillAppear)

- (void)viewDidLoad {
  [super viewDidLoad];

  CGFloat width = self.scrollView.bounds.size.width;
  CGFloat height = CGRectGetMaxY(self.textField2.frame);
  self.scrollView.contentSize = CGSizeMake(width, height);
}
+4
source share
1

, UIScrollView contentSize NSLayoutConstraint. a UIActionSheet ""...

Edit:

? , UIScrollView. , UIScrollView . .

, contentSize, - UIScrollView contentSize UIViewController - (void)viewDidLayoutSubviews.

,

- (void)viewDidLoad 
{
  [super viewDidLoad];

  CGFloat width = self.scrollView.bounds.size.width;
  CGFloat height = CGRectGetMaxY(self.textField2.frame);
  self.scrollView.contentSize = CGSizeMake(width, height);
}

:

- (void)viewDidLoad 
{
  [super viewDidLoad];

  // Any other code here...
}

- (void)viewDidLayoutSubviews
{
  [super viewDidLayoutSubviews];

  CGFloat width = self.scrollView.bounds.size.width;
  CGFloat height = CGRectGetMaxY(self.textField2.frame);
  self.scrollView.contentSize = CGSizeMake(width, height);
}

updateViewConstraints , ...

+2

Source: https://habr.com/ru/post/1542563/


All Articles