ran*_*dom 6 objective-c uiscrollview uiview uiviewanimation ios
我有一个UIViewController.在那是UITableView它在原产地绘制0,0.我也有一个UIScrollView被绘制,0,-80以便它在屏幕外,不可见.
当按下一个菜单按钮时,我将该UIViewController帧的动画设置为80px,以显示该帧UIScrollView.
这里的问题是UIScrollView根本没有回应.
如果我绘制UIScrollViewat the say 0,0,它在加载时可见,它可以正常工作.我甚至可以在屏幕上制作动画,然后返回屏幕,没有任何问题.
以下是我的视图在动画制作之前的样子:
_____________________________
| | Frame -> (0,-80, 320, 80)
| ScrollView | **Offscreen**
|_____________________________|
| | <- Original view (0,0,320,480)
| |
| |
| |
| |
| |
| Original View |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|_____________________________|
Run Code Online (Sandbox Code Playgroud)
当我制作动画时,我会执行以下操作:
[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;
}
}];
Run Code Online (Sandbox Code Playgroud)
现在我的视图在动画后看起来像这样:
_____________________________
| | Frame -> (0, -80, 320, 80)
| ScrollView |
|_____________________________|
| | <- Original view (0, 80, 320, 480)
| |
| |
| |
| |
| |
| Original View |
| |
| |
| |
| |
| |
| |
| |
|_____________________________|
| |
| **Offscreen** |
|_____________________________|
Run Code Online (Sandbox Code Playgroud)
我已经scrollView将我的子类更密切地倾听事件了:
.H
#import <UIKit/UIKit.h>
@interface UIScrollView_ExtraTouch : UIScrollView
@end
Run Code Online (Sandbox Code Playgroud)
.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
Run Code Online (Sandbox Code Playgroud)
动画后没有任何内容记录到日志中.我认为这意味着,因为框架处于-80,它认为它在屏幕外,因此不接受任何类型的动作.
它是否正确?如果有,有办法解决它吗?
滚动视图位于原始视图之外,因此您无法对其做出反应。要修复此问题,请创建一个足够大以包含整个内容区域的包装视图(scrollView 和 tableView 均作为子视图),将其添加到原始视图,并为该包装视图而不是原始视图设置动画。
因此包装视图将为 320x560,原始视图为 0,-80。然后根据需要将其上下移动 80。
| 归档时间: |
|
| 查看次数: |
385 次 |
| 最近记录: |