Skip to content

Instantly share code, notes, and snippets.

@yyjim
Created February 24, 2016 03:08
Show Gist options
  • Save yyjim/9c561718518a151e20d4 to your computer and use it in GitHub Desktop.
Save yyjim/9c561718518a151e20d4 to your computer and use it in GitHub Desktop.
EXP PagingScrollView
//
// PagingCollectionView.h
// PicCollage
//
// Created by yyjim on 2/22/16.
//
//
#import <UIKit/UIKit.h>
@interface PagingScrollView : UIView
@property (nonatomic) CGFloat pagingWidth;
@property (nonatomic) CGFloat pagingHeight;
@property (nonatomic) UIScrollView *scrollView;
@end
//
// PagingCollectionView.m
// PicCollage
//
// Created by yyjim on 2/22/16.
//
//
#import <Masonry/Masonry.h>
#import "PagingScrollView.h"
// =============================================================================
@interface PagingScrollView ()
@property (nonatomic) MASConstraint *widthContraint;
@property (nonatomic) MASConstraint *heightContraint;
@end
// =============================================================================
@implementation PagingScrollView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
}
return self;
}
- (void)setScrollView:(UIScrollView *)scrollView
{
[_scrollView removeFromSuperview];
_scrollView = scrollView;
[self addSubview:_scrollView];
[self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(self);
make.width.equalTo(@(self.pagingWidth)).priorityLow();
make.height.equalTo(@(self.pagingHeight)).priorityLow();
self.widthContraint = make.width.equalTo(self.mas_width).priorityHigh();
self.heightContraint = make.height.equalTo(self.mas_height).priorityHigh();
}];
}
- (void)setPagingWidth:(CGFloat)pagingWidth
{
if (_pagingWidth == pagingWidth) {
return;
}
_pagingWidth = pagingWidth;
if (_pagingWidth == 0) {
[self.widthContraint activate];
} else {
[self.widthContraint deactivate];
[self.scrollView mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.equalTo(@(_pagingWidth));
}];
}
}
- (void)setPagingHeight:(CGFloat)pagingHeight
{
if (_pagingHeight == pagingHeight) {
return;
}
_pagingHeight = pagingHeight;
if (_pagingHeight == 0) {
[self.heightContraint activate];
} else {
[self.heightContraint deactivate];
[self.scrollView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.equalTo(@(_pagingHeight));
}];
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment