Hello pratik!
I've reproduced the situation you've described in your question (at least I think so): a UIScrollView, a UIView inside the UIScrollView and an UIButton inside the UIView.
I tried taping touching the scroll view and moving my finger across the button and didn't get it to bounce to the top or anything like that. I also tried tapping the button after scrolling the scroll and it had no side effects too.
So my guess is that what you are dealing with is something like this: a UINavigationController with you UIScroll-UIView-UIButton UIViewController as a root view controller; after being tapped the UIButton pushes a new UIViewController to the UINavigationController; then you go back to the previous UIViewController in the UINavigationController stack and this is when you lose you scroll position.
If my guess is right than here's what you need to do.
Before pushing a new UIViewController save you scroll view's current content offset with the following code:
[[NSUserDefaults standardUserDefaults] setObject:NSStringFromCGPoint(theScrollView.contentOffset) forKey:@"ScrollViewLastContentOffset"];
And after you get back to you UIScrollView UIViewController use the following code in you viewWillAppear: method:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults stringForKey:@"ScrollViewLastContentOffset"] != nil) {
theScrollView.contentOffset = CGPointFromString([defaults stringForKey:@"ScrollViewLastContentOffset"]);
[defaults removeObjectForKey:@"ScrollViewLastContentOffset"];
}
}
Even if my guess wrong please do comment on my and Alan's answer and confirm/refute them for us to be able to help you. Would you mind also providing more details on your problem so we wouldn't need to guess what's going on exactly anymore.