UIScrollView 控制器 - 从嵌套笔尖更改滚动视图属性?

发布于 2024-12-04 05:44:06 字数 2642 浏览 0 评论 0原文

我目前正在开发一个使用scrollViewController 的应用程序,因为我需要垂直和水平滚动,以便加载NIB 的嵌套。

这一切都工作得很好,但是当我将 UIPicker 添加到我的一个嵌套笔尖中时,它不会滚动,我读到可以通过在 UIScrollView 中禁用滚动来轻松修复此问题,但是我不 100% 确定如何从其他类中执行此操作。

在mainView.m

@interface scrollViewController : UIViewController <UIScrollViewDelegate>{

    UIScrollView* scrollView;
    UIPageControl* pageControl;

    UIScrollView *vScrollView;
    UIScrollView *hScrollView;

    BOOL pageControlBeingUsed;
}

@property (nonatomic, retain) IBOutlet UIScrollView* scrollView;
@property (nonatomic, retain) IBOutlet UIPageControl* pageControl;

@property (nonatomic, retain) UIScrollView *vScrollView;
@property (nonatomic, retain) UIScrollView *hScrollView;

- (IBAction)changePage;

@end

中,

- (void)viewDidLoad
{
    [super viewDidLoad];

    CGRect bounds = self.view.bounds;

    // main guy is a horizontal scroller
    hScrollView = [[UIScrollView alloc] initWithFrame:bounds];
    hScrollView.contentSize = CGSizeMake(bounds.size.width * 2, bounds.size.height);
    hScrollView.delegate = self;
    [self.view addSubview:hScrollView];

    // the horizontal scroller contains a vertical scroller
    vScrollView = [[UIScrollView alloc] initWithFrame:bounds];
    vScrollView.contentSize = CGSizeMake(bounds.size.width, bounds.size.height * 2);
    vScrollView.delegate = self;
    [hScrollView addSubview:vScrollView];


    2ndView *view2 = [[2ndView alloc] initWithNibName:@"2ndView" bundle:nil];
    [vScrollView addSubview:view2.view];
    vScrollView.contentOffset = CGPointMake(0, bounds.size.height);

    mainView *vc = [[mainView alloc] initWithNibName:@"mainView" bundle:nil];
    vc.view.frame = CGRectOffset(bounds, 0, bounds.size.height); 
    [vScrollView addSubview:vc.view];


    // 3rd View
    ValidatorView *vc3 = [[ValidatorView alloc] initWithNibName:@"ValidatorView" bundle:nil];
    vc3.view.frame = CGRectOffset(bounds, bounds.size.width, 0); 

    [hScrollView addSubview:vc3.view]; 

    // enable paging in both directions
    hScrollView.pagingEnabled = TRUE;
    vScrollView.pagingEnabled = TRUE;

    hScrollView.showsHorizontalScrollIndicator = FALSE;
    vScrollView.showsVerticalScrollIndicator = FALSE;
    hScrollView.alwaysBounceHorizontal = FALSE;
    vScrollView.alwaysBounceVertical = FALSE;
    vScrollView.canCancelContentTouches =   NO;
    vScrollView.delaysContentTouches = NO;    
    hScrollView.bounces = FALSE;
    vScrollView.bounces = FALSE;
}

我创建了一个按钮,将 UIPicker 带到视图上,但是我希望它使用属性

vScrollView.scrollEnabled = NO; 更新滚动视图控制器中的 vScrollView;

对此的任何帮助将不胜感激。

谢谢亚伦

I'm currently working on an application which uses a scrollViewController as I need to have a vertical and horizontal scroll so it loads the NIB's nested.

This all worked fine but when I add a UIPicker into one of my nested nibs it does not scroll, I have read this can easily be fixed by disabling scrolling in the UIScrollView however I am not 100% sure how to do this from the other class.

scrollViewController.h

@interface scrollViewController : UIViewController <UIScrollViewDelegate>{

    UIScrollView* scrollView;
    UIPageControl* pageControl;

    UIScrollView *vScrollView;
    UIScrollView *hScrollView;

    BOOL pageControlBeingUsed;
}

@property (nonatomic, retain) IBOutlet UIScrollView* scrollView;
@property (nonatomic, retain) IBOutlet UIPageControl* pageControl;

@property (nonatomic, retain) UIScrollView *vScrollView;
@property (nonatomic, retain) UIScrollView *hScrollView;

- (IBAction)changePage;

@end

scrollViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];

    CGRect bounds = self.view.bounds;

    // main guy is a horizontal scroller
    hScrollView = [[UIScrollView alloc] initWithFrame:bounds];
    hScrollView.contentSize = CGSizeMake(bounds.size.width * 2, bounds.size.height);
    hScrollView.delegate = self;
    [self.view addSubview:hScrollView];

    // the horizontal scroller contains a vertical scroller
    vScrollView = [[UIScrollView alloc] initWithFrame:bounds];
    vScrollView.contentSize = CGSizeMake(bounds.size.width, bounds.size.height * 2);
    vScrollView.delegate = self;
    [hScrollView addSubview:vScrollView];


    2ndView *view2 = [[2ndView alloc] initWithNibName:@"2ndView" bundle:nil];
    [vScrollView addSubview:view2.view];
    vScrollView.contentOffset = CGPointMake(0, bounds.size.height);

    mainView *vc = [[mainView alloc] initWithNibName:@"mainView" bundle:nil];
    vc.view.frame = CGRectOffset(bounds, 0, bounds.size.height); 
    [vScrollView addSubview:vc.view];


    // 3rd View
    ValidatorView *vc3 = [[ValidatorView alloc] initWithNibName:@"ValidatorView" bundle:nil];
    vc3.view.frame = CGRectOffset(bounds, bounds.size.width, 0); 

    [hScrollView addSubview:vc3.view]; 

    // enable paging in both directions
    hScrollView.pagingEnabled = TRUE;
    vScrollView.pagingEnabled = TRUE;

    hScrollView.showsHorizontalScrollIndicator = FALSE;
    vScrollView.showsVerticalScrollIndicator = FALSE;
    hScrollView.alwaysBounceHorizontal = FALSE;
    vScrollView.alwaysBounceVertical = FALSE;
    vScrollView.canCancelContentTouches =   NO;
    vScrollView.delaysContentTouches = NO;    
    hScrollView.bounces = FALSE;
    vScrollView.bounces = FALSE;
}

In mainView.m I have created a button which brings a UIPicker onto the view, however I want it to update the vScrollView in scrollViewController with the property

vScrollView.scrollEnabled = NO;

Any help on this would be appreciated.

Thanks Aaron

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

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

发布评论

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

评论(1

巾帼英雄 2024-12-11 05:44:06

您可以在应用程序委托类中拥有一个指向滚动视图控制器的实例变量,然后您可以将该实例变量的 scrollEnabled 设为 NO

You can have an instance variable in your application delegate class that points to your scrollViewController and then you can use scrollEnabled of that instance variable to NO

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