1
我目前正在使用scrollViewController的應用程序,因爲我需要有一個垂直和水平滾動,因此它加載NIB的嵌套。UIScrollView控制器 - 從嵌套的筆尖更改scrollview屬性?
這一切工作正常,但是當我添加一個UIPicker到我的一個嵌套鳥嘴它不滾動,我讀過這可以很容易地通過禁用UIScrollView滾動修復,但我不是100%確定如何做到這一點來自其他班級。
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;
}
在mainView.m我創建了一個按鈕,這帶來了UIPicker到觀點,但是我想它來更新vScrollView在具有屬性的scrollViewController
vScrollView.scrollEnabled = NO;
任何幫助,將不勝感激。
感謝阿龍
你有我怎麼能一個例子做這個? – MonkeyBlue
可以中游應用程序委託在這樣 '[[UIApplication的sharedApplication]代表]的應用程序的任何地方'(它設置爲您的應用程序的委託變量) 如果你有一個像 '@財產在你的AppDelegate屬性( nonatomic,retain)UIScrollViewController * yourScrollController;' 無論何時您創建scrollViewController將其設置爲您的ScrollController。 然後當你想禁用它只是做到這一點。 MyAppDelegate(無論它的名字是)*德爾= [[UIApplication的sharedApplication]委託];' 'del.yourScrollController.vScrollView.scrollEnabled = NO;' 篩選。 –
謝謝,這是完美的意義只是一個額外的問題我的應用程序委託加載scrollViewController作爲一個視圖,這是屬性的位置?我是否需要改變它的工作方式,因爲目前我認爲應用程序委託並不存在任何直接聯繫。 – MonkeyBlue