Iphone 问题:UIScrollview反弹会使父UIScrollview反弹
我在全屏UIScrollview(a)中有一个全屏UIScrollview(B)Iphone 问题:UIScrollview反弹会使父UIScrollview反弹,iphone,cocoa-touch,uiscrollview,bounce,Iphone,Cocoa Touch,Uiscrollview,Bounce,我在全屏UIScrollview(a)中有一个全屏UIScrollview(B) A的contentsize=水平页数 B的内容大小=子页面的数量 在B里面,我有一个小的UIscrollview(C),它在与B相同的方向上滚动。。。垂直方向也是如此 当C疯狂滚动时,当contentSize结束时,它会产生一种硬反弹效果 问题是:它也会对B产生反弹效应!!!!有没有一种方法可以在不抑制父母和孩子之间的反弹效应的情况下,抑制父母和孩子之间反弹效应的污染 谢谢苹果的文档警告不要使用类似的设计。发件
- A的contentsize=水平页数
- B的内容大小=子页面的数量
- 在B里面,我有一个小的UIscrollview(C),它在与B相同的方向上滚动。。。垂直方向也是如此
谢谢苹果的文档警告不要使用类似的设计。发件人: 重要提示:不应在UIScrollView对象中嵌入UIWebView或UITableView对象。如果这样做,可能会导致意外行为,因为两个对象的触摸事件可能会混淆并错误处理 出于您发现的原因,我将此警告扩展到嵌套的UIScrollView 您可以通过大致执行mobile Safari浏览器所做的操作来模拟嵌套的A/B/C UIScrollView。用户处于“网页选择”模式(A&B视图)或“查看网页”模式(C视图)。Safari的自定义WebView控制器中的一个按钮允许用户跳出“查看网页”模式跳转到“网页选择”模式,这是一个UIScrollView,其中包含当前活动的每个网页的缩略图 因此,在您的例子中,这意味着将C从嵌套的UIScrollView中拉出,向显示a&B视图控制器的C视图控制器添加一个按钮,并可能创建另一个控制器类将其粘合在一起 我还主张将A&B合并到一个UIScrollView中。根据now 要创建丰富的用户体验,您可能需要在应用程序中嵌套滚动视图。在iOS 3.0之前,要做到这一点即使不是不可能,也是很困难的。在iOS 3.0中,此功能完全受支持并自动工作 因此,嵌套滚动视图非常好>iOS 3。为了回答您的问题,我在将容器视图添加到scrollview B之前,将scrollview C作为子视图添加到了“容器”UIView中。它似乎停止了向下拖动父滚动视图的反弹,尽管我必须非常用力和快速地滑动,以使其显示您在没有容器视图的情况下描述的行为
@interface TiledScrollView : UIScrollView @end
@implementation TiledScrollView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if(self)
{
self.layer.borderColor = [UIColor whiteColor].CGColor;
self.layer.borderWidth = 10.f;
}
return self;
}
- (void)setContentSize:(CGSize)contentSize
{
[super setContentSize:contentSize];
BOOL horizontal = contentSize.width > self.frame.size.width;
if(horizontal)
{
CGFloat col = self.contentSize.width / 10.f;
for (int i = 0; i < 10; i++)
{
UIView * view = [[UIView alloc] initWithFrame:CGRectMake(i * col, 0, col, self.contentSize.height)];
view.backgroundColor = [UIColor colorWithHue:(arc4random() % 100) / 100.f saturation:1.f brightness:1.f alpha:1.f];
[self addSubview:view];
}
}
else
{
CGFloat row = self.contentSize.height / 10.f;
for (int i = 0; i < 10; i++)
{
UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, i * row, self.contentSize.width, row)];
view.backgroundColor = [UIColor colorWithHue:(arc4random() % 100) / 100.f saturation:1.f brightness:1.f alpha:1.f];
[self addSubview:view];
}
}
}
@end
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect bounds = [UIScreen mainScreen].bounds;
TiledScrollView * A = [[TiledScrollView alloc] initWithFrame:CGRectMake(0, 0, bounds.size.width, bounds.size.height)];
TiledScrollView * B = [[TiledScrollView alloc] initWithFrame:CGRectMake(0, 0, bounds.size.width, bounds.size.height / 2.f)];
TiledScrollView * C = [[TiledScrollView alloc] initWithFrame:CGRectMake(0, 0, bounds.size.width, bounds.size.height / 4.f)];
[A setContentSize:CGSizeMake(bounds.size.width * 4, bounds.size.height)];
[B setContentSize:CGSizeMake(bounds.size.width, bounds.size.height * 4)];
[C setContentSize:CGSizeMake(bounds.size.width, bounds.size.height * 4)];
UIView * container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, bounds.size.width, bounds.size.height / 4.f)];
[container addSubview:C];
[B addSubview:container];
[A addSubview:B];
[self.view addSubview:A];
}
@end
@界面平铺滚动视图:UIScrollView@end
@实现平铺滚动视图
-(id)initWithFrame:(CGRect)帧
{
self=[super initWithFrame:frame];
如果(自我)
{
self.layer.borderColor=[UIColor whiteColor].CGColor;
self.layer.borderWidth=10.f;
}
回归自我;
}
-(void)setContentSize:(CGSize)contentSize
{
[超级设置contentSize:contentSize];
BOOL horizontal=contentSize.width>self.frame.size.width;
如果(水平)
{
CGFloat col=self.contentSize.width/10.f;
对于(int i=0;i<10;i++)
{
UIView*view=[[UIView alloc]initWithFrame:CGRectMake(i*col,0,col,self.contentSize.height)];
view.backgroundColor=[UIColor colorWithHue:(arc4random()%100)/100.f饱和度:1.f亮度:1.f alpha:1.f];
[自添加子视图:视图];
}
}
其他的
{
CGFloat row=self.contentSize.height/10.f;
对于(int i=0;i<10;i++)
{
UIView*view=[[UIView alloc]initWithFrame:CGRectMake(0,i*行,self.contentSize.width,行)];
view.backgroundColor=[UIColor colorWithHue:(arc4random()%100)/100.f饱和度:1.f亮度:1.f alpha:1.f];
[自添加子视图:视图];
}
}
}
@结束
#导入“ViewController.h”
@界面视图控制器()
@结束
@实现视图控制器
-(无效)viewDidLoad
{
[超级视图下载];
CGRect边界=[UIScreen mainScreen].bounds;
TiledScrollView*A=[[TiledScrollView alloc]initWithFrame:CGRectMake(0,0,bounds.size.width,bounds.size.height)];
TiledScrollView*B=[[TiledScrollView alloc]initWithFrame:CGRectMake(0,0,bounds.size.width,bounds.size.height/2.f)];
TiledScrollView*C=[[TiledScrollView alloc]initWithFrame:CGRectMake(0,0,bounds.size.width,bounds.size.height/4.f)];
[A setContentSize:CGSizeMake(bounds.size.width*4,bounds.size.height)];
[B setContentSize:CGSizeMake(bounds.size.width,bounds.size.height*4)];
[C setContentSize:CGSizeMake(bounds.size.width,bounds.size.height*4)];
UIView*container=[[UIView alloc]initWithFrame:CGRectMake(0,0,bounds.size.width,bounds.size.height/4.f)];
[容器添加子视图:C];
[B添加子视图:容器];
[A添加子视图:B];
[self.view addSubview:A];
}
@结束
当你的手指开始弹跳时,它是否在C以外(即在B内)?移动从C内开始,是的,当它开始弹跳时,手指在C外。为什么?