I have a UIViewController
. Within that is a UITableView
which is drawn at origin 0,0
. I also have a UIScrollView
that is drawn at 0,-80
so that it is off screen and not visible.
When a menu button is pressed, I animate the UIViewController
's frame down 80px to reveal the UIScrollView
.
The problem here is that the UIScrollView
does not respond at all.
If I draw the UIScrollView
at say 0,0
, where it IS visible on load, it works fine. I can even animate it off screen then back on screen with no issue.
Here is how my view looks before animating:
_____________________________
| | Frame -> (0,-80, 320, 80)
| ScrollView | **Offscreen**
|_____________________________|
| | <- Original view (0,0,320,480)
| |
| |
| |
| |
| |
| Original View |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|_____________________________|
When I animate I do the following:
[UIView animateWithDuration:0.3
delay:0.0
options:(UIViewAnimationOptionAllowUserInteraction |
UIViewAnimationOptionCurveEaseIn)
animations:^{
self.view.frame = CGRectMake(0.0, (self.view.frame.origin.y + container.frame.size.height), self.view.frame.size.width, self.view.frame.size.height);
scroll.userInteractionEnabled = YES;
}
completion:^(BOOL finished) {
if (scrollLoaded == NO) {
[self loadFavorites];
scrollLoaded = YES;
}
}];
Now my view looks like this after animating:
_____________________________
| | Frame -> (0, -80, 320, 80)
| ScrollView |
|_____________________________|
| | <- Original view (0, 80, 320, 480)
| |
| |
| |
| |
| |
| Original View |
| |
| |
| |
| |
| |
| |
| |
|_____________________________|
| |
| **Offscreen** |
|_____________________________|
I have subclassed my scrollView
to listen more closely for events:
.h
#import <UIKit/UIKit.h>
@interface UIScrollView_ExtraTouch : UIScrollView
@end
.m
#import "UIScrollView+ExtraTouch.h"
@implementation UIScrollView_ExtraTouch
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"scrollview touchesBegan");
[self.nextResponder touchesBegan:touches withEvent:event];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"scrollview touchesMoved");
if(!self.dragging){
[self.nextResponder touchesMoved:touches withEvent:event];
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"scrollview touchesEnded");
[self.nextResponder touchesEnded:touches withEvent:event];
}
@end
Nothing goes to the log after the animation. Which I think means that since the frame is at -80
, it believes it to be off screen, thus not receive any type of action.
Is this correct? If so is there a way to fix it?
The scroll view is outside of the original view so you cannot react with it. To fix create a wrapper view that is large enough to contain the whole content area(with scrollView & tableView both as subViews), add it to the original view, and animate this wrapper view instead of original view.
So wrapper view will be 320x560, and at 0,-80 in original view. Then move it up and down 80 as needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With