2013-08-04 93 views
2

將按鈕拖動到我的滾動視圖後,窗口不再滾動!如果我刪除按鈕,現在滾動工作。UIScrollView內的UIButton禁用滾動

之前有人遇到過這個問題嗎?

//ScrollViewController.h 
@property (weak, nonatomic) IBOutlet UIScrollView *scroller; 


//ScrollViewController.m 
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 

    [self.scroller setScrollEnabled:YES]; 
    [self.scroller setContentSize:CGSizeMake(320, 700)]; 
} 

enter image description here

+0

這個【答】解決了iOS 8下的問題[1] [1]:http://stackoverflow.com/a/25900859/3433059 – Userich

回答

2

其實,這只是工作。

有人可以解釋爲什麼這項工作?

- (void)viewDidLayoutSubviews 
{ 
    [super viewDidLayoutSubviews]; 
    [self.scroller setScrollEnabled:YES]; 
    [self.scroller setContentSize:CGSizeMake(320, 700)]; 
} 
0

在viewDidLoad中添加:添加移動代碼viewDidLayoutSubiews後

self.scroller.canCancelContentTouches = YES; 
+2

爲什麼這是必要的一些解釋可能會有所幫助。 – 2013-08-04 20:20:53

0

UIScrollView的子類和下方添加代碼到.m文件,做iOS的下解決我的滾動凍結問題8.

代碼:

- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view 
{ 
    UITouch *touch = [touches anyObject]; 

    if(touch.phase == UITouchPhaseMoved) 
    { 
     return NO; 
    } 
    else 
    { 
     return [super touchesShouldBegin:touches withEvent:event inContentView:view]; 
    } 
} 

將此溶液pasta12的回答中發現https://stackoverflow.com/a/25900859/3433059