问题:UIScrollview 弹跳使父 UIScrollview 弹跳

发布于 2024-09-29 06:57:26 字数 322 浏览 8 评论 0原文

我在全屏 UIScrollview(A) 中有一个全屏 UIScrollview(B)。

  • A 的内容大小 = 水平页数

  • B 的内容大小 = 垂直子页数

  • 在 B 内部,我有一个小的 UIscrollview (C),其滚动方向与 B 相同...所以也垂直。

当 C 疯狂滚动时,当到达 contentSize 末尾时,它会产生硬弹跳效果。

问题是:它还会在 B 上产生弹跳效果!!!!有没有办法抑制父母和孩子之间的反弹效应的污染,而不抑制双方的反弹效应。

谢谢

I have a fullscreen UIScrollview(B) in a fullscreen UIScrollview(A).

  • A has a contentsize = number of page Horizontally

  • B has a contentsize = number of Subpage Vertically

  • Inside B , I have a small UIscrollview (C) that scroll in the same direction than B... So vertically too.

When C is wildly scrolling, it creates a hard bouncing effect when the end of the contentSize is arrived.

the problem : IT CREATES ALSO A BOUNCING EFFET ON B!!!! is there a way to suppress this contamination of the bounce effect between parents and childs without suppress the bounce effet of both.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

御守 2024-10-06 06:57:26

苹果文档警告不要类似的设计。来自文档

重要提示:您不应在 UIScrollView 对象中嵌入 UIWebView 或 UITableView 对象。如果这样做,可能会导致意外行为,因为两个对象的触摸事件可能会混淆并错误处理。

由于您发现的原因,我会将此警告扩展到嵌套的 UIScrollViews。

您可以通过大致执行移动 Safari 浏览器的操作来将其从嵌套的 A/B/C UIScrollViews 中模拟出来。用户要么处于“网页选择”模式(您的 A&B 视图),要么处于“查看网页”模式(您的 C 视图)。 Safari 的自定义 WebView 控制器中的按钮允许用户从“查看网页”模式跳转到“网页选择”模式,该模式是一个 UIScrollView,其中包含当前活动的每个页面的缩略图。

因此,在您的情况下,这意味着将 C 从嵌套的 UIScrollViews 中拉出,向 C 视图控制器添加一个按钮来呈现 A&B 视图控制器,并且可能创建另一个控制器类将它们粘合在一起。

我还主张将 A 和 B 合并到一个 UIScrollView 中。

The Apple documentation warns against similar designs. From the docs:

Important: You should not embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled.

I would extend this warning to nested UIScrollViews for the reasons you've discovered.

You can pull it off an analog of the nested A/B/C UIScrollViews by doing roughly what the mobile Safari browser does. The user is either in "web page select" mode (your A&B views) or in "view web page" mode (Your C view). A button in Safari's custom WebView controller allows the user to jump out of "view web page" mode to "web page select" mode, which is a UIScrollView with thumbnails of each of the pages currently active.

So, in your case, that would mean pulling C out of the nested UIScrollViews, adding a button to the C view controller that presents the A&B view controller, and maybe creating another controller class to glue it all together.

I'd also advocate combining A&B into a single UIScrollView.

古镇旧梦 2024-10-06 06:57:26

根据 Apple iOS 滚动视图编程指南现在..

为了创建丰富的用户体验,您可能需要在应用程序中嵌套滚动视图。在 iOS 3.0 之前,要实现这一点即使不是不可能,也是很困难的。在 iOS 3.0 中,此功能得到完全支持并自动运行。

所以嵌套滚动视图是完全没问题的> iOS 3。为了回答你的问题,我将滚动视图 C 作为子视图添加到“容器”UIView - 在将该容器视图添加到滚动视图 B 之前。似乎阻止了弹跳将父滚动视图向下拉,尽管我确实必须漂亮地滑动努力并快速地使其在没有容器视图的情况下表现出您所描述的行为。

@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

According to the Apple iOS Scroll View Programming Guide now..

To create a rich user experience, you may want to nest scroll views in your application. Before iOS 3.0 it was difficult, if not impossible to accomplish this. In iOS 3.0, this functionality is fully supported and works automatically.

So nesting scrollviews is perfectly fine > iOS 3. To answer your question, I added scrollview C as a subview to a "container" UIView - before adding that container view to scrollview B. Seems to stop the bounce pulling the parent scroll view down, although I did have to swipe pretty hard and fast to make it exhibit the behaviour you described without the container view.

@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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文