scrollView不能拖动

地上大螃蟹 发布于 2015/09/07 21:32
阅读 964
收藏 0
iOS

一下是关于scrollView的设定

@interface ZFSlideBarContentView : UIView

@property (nonatomic,strong)NSMutableArray *scrollView;

@property (nonatomic,strong)UIScrollView *views;

@end


@implementation ZFSlideBarContentView

-(instancetype)init{

    if (self = [super init]) {

            self.scrollView = [NSMutableArray array];

            [self initScrollView];

            [self initContentView];

    }

        return self;

}

-(void)initScrollView{

    self.views = [[UIScrollView alloc]init];

    CGFloat screenW = [UIScreen mainScreen].bounds.size.width;

    CGFloat screenH = [UIScreen mainScreen].bounds.size.height;

    self.views.frame = CGRectMake(0, 80,screenW ,screenH-80);

    self.views.contentSize = CGSizeMake(screenW*4, screenH-80);

    self.views.pagingEnabled = YES;

    self.views.scrollEnabled = YES;

    self.views.userInteractionEnabled = YES;

    self.views.backgroundColor = [UIColor clearColor];

    for (int i = 0 ; i<4; i++) {

        UIView *view = [[UIView alloc]init];

        [_scrollView addObject:view];

    }

    [self addSubview:self.views];

}

-(void)initContentView{

   

    for (UIView * view in _scrollView) {

        

        NSInteger index =[_scrollView indexOfObject:view];

        CGFloat screenBoundsWide = [UIScreen mainScreen].bounds.size.width;

        view.frame = CGRectMake(0 + index*screenBoundsWide, 0, screenBoundsWide,600);

        switch (index) {

            case 0:

                view.backgroundColor = [UIColor blackColor];

                break;

            case 1:

                view.backgroundColor = [UIColor blueColor];

                break;

            case 2:

                view.backgroundColor = [UIColor redColor];

                break;

            default:

                view.backgroundColor = [UIColor greenColor];

                break;

        }

        NSLog(@"+++%f",view.frame.origin.x);

        [_views addSubview:view];

    }

    

}

在VC中代码:

@interface MainMenuViewController ()

@property (nonatomic,strong)ZFSlideBarContentView *contentViews;

@end

@implementation MainMenuViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    ZFSlideBar *slide = [[ZFSlideBar alloc]init];

    slide.titleList = @[@"我的",@"推荐",@"曲库",@"视频"];

    slide.itemColor = [UIColor whiteColor];

    slide.slideColor = [UIColor blueColor];

    [self.view addSubview:slide];

    self.contentViews = [[ZFSlideBarContentView alloc]init];

    [self.view addSubview:self.contentViews];

  //  NSLog(@"%@",views.subviews);

 //   NSLog(@"viewDidLoad w:%f,h:%f",self.contentViews.views.contentSize.width,self.contentViews.views.contentSize.height);

 //   NSLog(@" frame  ---viewDidLoad w:%f,h:%f",self.contentViews.views.frame.size.width,self.contentViews.views.frame.size.height);

}

auto layout也取消了 可还是动不了

加载中
0
SimpleName
SimpleName

    CGFloat screenW = [UIScreen mainScreen].bounds.size.width;

CGFloat screenH = [UIScreen mainScreen].bounds.size.height;

self.views = [[UIScrollView alloc]initWithFrame: CGRectMake(0, 80,screenW*4 ,screenH)];这样写试试

SimpleName
SimpleName
回复 @地上大螃蟹 : 你为什么不在控制器里添加ScrollView要在View上贴ScrollView ,你换成控制器把 问题估计就出在这里
地上大螃蟹
改了还是不行。。
返回顶部
顶部