I got stuck with the strange behavior of UIScrollView that I cannot click on the UIButton after I enlarge the contentSize of the UIScrollView.
What I wanted to do:
You can add a button say submit and another button as subview of the scrollview.Keep your another button hidden in start and call setContentsize. now when user clicks on submit button then set another button to visible and again call set content size.In this way you would be able to achieve what you want to.
i have tried to generate scenario for you.I have tried this on view based application with storyboard without auto layout.
so in story board do some thing like this:
#import
@interface ALViewController : UIViewController
@property (nonatomic, weak) IBOutlet UIScrollView *scroll;
@property (nonatomic, weak) IBOutlet UIButton *btn1; @property (nonatomic, weak) IBOutlet UIButton *btn2;
=========== implementation:
#import "ALViewController.h"
@interface ALViewController ()
@end
@implementation ALViewController
- (void)viewDidLoad
{ [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [self.btn2 setHidden:YES];
[self adjustContentSize];
}
-(void)adjustContentSize { CGRect contentRect = CGRectZero; for (UIView *view in self.scroll.subviews) { if (![view isHidden]) { contentRect = CGRectUnion(contentRect, view.frame); } }
self.scroll.contentSize = contentRect.size;
}
-(IBAction)btnClicked:(id)sender { UIButton *btn = (UIButton *)sender; if (btn.tag ==1) { [self.btn2 setHidden:FALSE]; [self adjustContentSize]; }
}
@end
and in storyboard some thing like this:
@end
for your information:view frame 0,0,768,1024 scroll frame: 0,0,768,1024 btn1 frame: 361, 753, 46, 30 btn2 frame: 351, 1032, 46, 30
run your code : at first your scroll view would be unscrollable because we have set btw 2 to be hidden and set content size.As soon as you will be clicking on btn 1, see code we are making btn 2 visible again and calling set content size.
Conclusion:
the scrollview content size looks for its visible contain of which we can take benefit of.
thanks and regards.