关于Masonry框架约束ScrollView,图片横向滚动时出现的问题,用过的大神们进来指点下


RT,同样的代码,在7.1版本运行完全没问题,到了8.1以上的版本就会露出了后面的scrollView,求解,先上图吧 图片描述

然后是我的代码,大神们帮忙看看是哪里出了问题
@interface MainVC ()
@property(nonatomic,strong)UIScrollView * adScrollView;
@property(nonatomic,assign)NSInteger Imgnum;
@end

@implementation MainVC
- (void)viewDidLoad
{
[super viewDidLoad];
self.Imgnum = 2 ;
[self createAdScrollView:self.Imgnum];
}

pragma mark - ADSCrollView

-(void)createAdScrollView:(int)imageCount
{
WS(mv);//#define WS(weakSelf) __weak __typeof(&*self)weakSelf = self;
UIView * view = [[UIView alloc] init];
view.backgroundColor = [UIColor blueColor];
[self.view addSubview:view];


 //创建一个View,用来装scrollView
[view mas_makeConstraints:^(MASConstraintMaker *make) {
    make.edges.equalTo(mv.view).with.insets
    (UIEdgeInsetsMake(130,0,mv.view.bounds.size.height/3*1-44,0));
}];

self.adScrollView = [[UIScrollView alloc] init];
self.adScrollView.bounces = NO;
self.adScrollView.showsVerticalScrollIndicator = NO;
self.adScrollView.showsHorizontalScrollIndicator = NO;
self.adScrollView.backgroundColor = [UIColor blackColor];
[view addSubview:self.adScrollView];
self.automaticallyAdjustsScrollViewInsets = YES;

//scrollView约束
[self.adScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.edges.equalTo(view);
}];

//scrollview里放个View
UIView *container = [[UIView alloc] init];
[self.adScrollView addSubview:container];
[container mas_makeConstraints:^(MASConstraintMaker *make) {
    make.edges.equalTo(mv.adScrollView);
    make.height.equalTo(mv.adScrollView);
}];
//设置imageView
[self loadImageNum:imageCount And:container];

}

//要把图片改名成ad1,ad2,ad3.....这种格式
-(void)loadImageNum:(int)count And:(UIView * )view
{
WS(mv);
UIImageView *lastView = nil;
for ( int i = 1 ; i <= count ; ++i )
{
UIImageView * subv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"ad%d",i]]];
[view addSubview:subv];


 [subv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.and.bottom.equalTo(view);
        make.width.mas_equalTo(mv.view.bounds.size.width);
        make.height.mas_equalTo(view);

        if ( lastView )
        {
            make.left.mas_equalTo(lastView.mas_right);
        }
        else
        {
            make.left.mas_equalTo(view.mas_left);
        }
    }];

    lastView = subv;
}
[view mas_makeConstraints:^(MASConstraintMaker *make) {
    make.right.equalTo(lastView.mas_right);
}];

}

masonry ios uiscrollview

Cosmo 10 years, 3 months ago

结贴,忘了加这句self.automaticallyAdjustsScrollViewInsets = NO;

konoka answered 10 years, 3 months ago

Your Answer