Animation of objects from turning off the screen

I have a UIViewController . Inside this is a UITableView , which is drawn at the beginning of 0,0 . I also have a UIScrollView that draws at 0,-80 , so that it is turned off and not showing.

When the menu button is pressed, I am animating a UIViewController from below 80px to show a UIScrollView .

The problem here is that the UIScrollView not responding at all.

If I draw a UIScrollView , say 0,0 , where it displays when loading, it works fine. I can even revive it from the screen, and then return to the screen without any problems.


Here's what my gaze looks like before the animation:

  _____________________________ | | Frame -> (0,-80, 320, 80) | ScrollView | **Offscreen** |_____________________________| | | <- Original view (0,0,320,480) | | | | | | | | | | | Original View | | | | | | | | | | | | | | | | | | | | | |_____________________________| 

When I live, 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 after the animation:

  _____________________________ | | Frame -> (0, -80, 320, 80) | ScrollView | |_____________________________| | | <- Original view (0, 80, 320, 480) | | | | | | | | | | | Original View | | | | | | | | | | | | | | | |_____________________________| | | | **Offscreen** | |_____________________________| 

I have subclassed my scrollView to listen more closely to events:

.h

 #import <UIKit/UIKit.h> @interface UIScrollView_ExtraTouch : UIScrollView @end 

wow

 #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 magazine after the animation. I think this means that since the frame is at -80 , it believes that it is off, so it does not receive any action.

It is right? If so, can this be fixed?

+6
source share
1 answer

The scroll view is outside the original view, so you cannot respond to it. To fix this, create a shell view that is large enough to contain the entire content area (using scrollView and tableView as a subspecies), add it to the original view and animate that kind of shell instead of the original one.

Thus, the presentation of the wrapper will be 320x560, and at 0, -80 in its original form. Then move it up and down as needed.

+1
source

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


All Articles