【问题标题】:put UIScrollView on a CollectionViewCell but the scrollview can not scroll将 UIScrollView 放在 CollectionViewCell 上,但滚动视图无法滚动
【发布时间】:2015-05-28 07:24:43
【问题描述】:

我将UIScrollView 放在CollectionViewCell 上,但scrollview 无法滚动

#import <UIKit/UIKit.h>


@interface MyCollectionViewCell : UICollectionViewCell<UIScrollViewDelegate>{

    IBOutlet UIScrollView *toolsScrollView;


}


@end

@implementation MyCollectionViewCell

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        //wangzheng
        self = [super initWithFrame:frame];
        if (self) {
            NSArray *nibView =  [[NSBundle mainBundle] loadNibNamed:@"MyCollectionViewCell"owner:self options:nil];
            UIView *bw = [nibView objectAtIndex:0] ;
            [self.contentView addSubview:bw];
            toolsScrollView.delegate=self;


            UIView *toolView1 = [[UIView alloc] init];
            toolView1.backgroundColor = [UIColor blackColor];
            toolView1.frame = CGRectMake(300, 0, 80, 150);
            [toolsScrollView addSubview:toolView1];


            toolsScrollView.delegate=self;
            [toolsScrollView setContentSize:CGSizeMake(400 * 2, toolsScrollView.frame.size.height)];
            toolsScrollView.showsVerticalScrollIndicator = NO;
            toolsScrollView.showsHorizontalScrollIndicator = NO;
            toolsScrollView.delegate = self;
            toolsScrollView.userInteractionEnabled=true;
            toolsScrollView.scrollEnabled=true;
        }
        return self;
    }
    return self;
}

IBOutlet UIScrollView *toolsScrollView 链接到 XIB 中的 UIScrollView

滚动视图不能滚动,函数scrollViewDidScroll永远不会被触发

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    return;

}

【问题讨论】:

  • collectionView 不会从 scrollView 窃取触摸事件吗?
  • UICollectionViewCell 是 UIView 的子类
  • 你的collectionView中有相关代码吗?

标签: ios iphone uiscrollview uicollectionview


【解决方案1】:

可能的问题:

  1. toolsScrollView 变量未连接且未指向有效的滚动视图,或者,
  2. 从 nib 加载后,toolsScrollView 的框架不正确。或者,

3.它实际上在滚动但不可见,因此出于测试目的启用了以下 -

toolsScrollView.showsVerticalScrollIndicator = YES;
toolsScrollView.showsHorizontalScrollIndicator = YES;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-30
    • 2021-03-23
    • 2013-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多