Skip to content

Commit

Permalink
修改frame category,避免冲突
Browse files Browse the repository at this point in the history
  • Loading branch information
Roylee-ML committed Aug 15, 2016
1 parent 456f5b8 commit bfb29e9
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 134 deletions.
6 changes: 0 additions & 6 deletions SwipeTableView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
7D2C2AB01D32A7AD00C6A234 /* onepiece_kiudai.png in Resources */ = {isa = PBXBuildFile; fileRef = 7D2C2A951D32A7AD00C6A234 /* onepiece_kiudai.png */; };
7D2C2AB11D32A7AD00C6A234 /* STImageController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D2C2A981D32A7AD00C6A234 /* STImageController.m */; };
7D2C2AB21D32A7AD00C6A234 /* STListController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D2C2A9A1D32A7AD00C6A234 /* STListController.m */; };
7D2C2AB31D32A7AD00C6A234 /* STRefreshController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D2C2A9C1D32A7AD00C6A234 /* STRefreshController.m */; };
7D2C2AB41D32A7AD00C6A234 /* STViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D2C2A9E1D32A7AD00C6A234 /* STViewController.m */; };
7D2C2AB51D32A7AD00C6A234 /* github.png in Resources */ = {isa = PBXBuildFile; fileRef = 7D2C2AA01D32A7AD00C6A234 /* github.png */; };
7D2C2AB61D32A7AD00C6A234 /* STRefreshHeader.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D2C2AA31D32A7AD00C6A234 /* STRefreshHeader.m */; };
Expand Down Expand Up @@ -51,8 +50,6 @@
7D2C2A981D32A7AD00C6A234 /* STImageController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STImageController.m; sourceTree = "<group>"; };
7D2C2A991D32A7AD00C6A234 /* STListController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STListController.h; sourceTree = "<group>"; };
7D2C2A9A1D32A7AD00C6A234 /* STListController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STListController.m; sourceTree = "<group>"; };
7D2C2A9B1D32A7AD00C6A234 /* STRefreshController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STRefreshController.h; sourceTree = "<group>"; };
7D2C2A9C1D32A7AD00C6A234 /* STRefreshController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STRefreshController.m; sourceTree = "<group>"; };
7D2C2A9D1D32A7AD00C6A234 /* STViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = STViewController.h; sourceTree = "<group>"; };
7D2C2A9E1D32A7AD00C6A234 /* STViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = STViewController.m; sourceTree = "<group>"; };
7D2C2AA01D32A7AD00C6A234 /* github.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = github.png; sourceTree = "<group>"; };
Expand Down Expand Up @@ -123,8 +120,6 @@
7D2C2A9A1D32A7AD00C6A234 /* STListController.m */,
7D2C2A9D1D32A7AD00C6A234 /* STViewController.h */,
7D2C2A9E1D32A7AD00C6A234 /* STViewController.m */,
7D2C2A9B1D32A7AD00C6A234 /* STRefreshController.h */,
7D2C2A9C1D32A7AD00C6A234 /* STRefreshController.m */,
7D2C2A971D32A7AD00C6A234 /* STImageController.h */,
7D2C2A981D32A7AD00C6A234 /* STImageController.m */,
);
Expand Down Expand Up @@ -349,7 +344,6 @@
7DFB6ACE1CAEBCC600C2F0D3 /* main.m in Sources */,
7D2C2AB41D32A7AD00C6A234 /* STViewController.m in Sources */,
7D2C2AB11D32A7AD00C6A234 /* STImageController.m in Sources */,
7D2C2AB31D32A7AD00C6A234 /* STRefreshController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Binary file not shown.
70 changes: 37 additions & 33 deletions SwipeTableView/SwipeTableView/SwipeTableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ - (void)layoutSubviews {
self.contentView.frame = self.bounds;
self.layout.itemSize = self.bounds.size;
self.swipeHeaderBarScrollDisabled &= nil == _swipeHeaderView;
self.swipeHeaderBar.top = _swipeHeaderView.bottom;
self.swipeHeaderBar.st_top = _swipeHeaderView.st_bottom;
if (_swipeHeaderBarScrollDisabled) {
_swipeHeaderBar.top = _swipeHeaderTopInset;
_swipeHeaderBar.st_top = _swipeHeaderTopInset;
}
}

Expand All @@ -169,9 +169,9 @@ - (void)setSwipeHeaderView:(UIView *)swipeHeaderView {
[_swipeHeaderView removeFromSuperview];
[self addSubview:swipeHeaderView];

_swipeHeaderView = swipeHeaderView;
_swipeHeaderView.y += _swipeHeaderTopInset;
_headerInset = _swipeHeaderView.bounds.size.height;
_swipeHeaderView = swipeHeaderView;
_swipeHeaderView.st_y += _swipeHeaderTopInset;
_headerInset = _swipeHeaderView.bounds.size.height;

BOOL isSTHeaderView = [swipeHeaderView isKindOfClass:STHeaderView.class];
if (isSTHeaderView) {
Expand All @@ -188,9 +188,9 @@ - (void)setSwipeHeaderBar:(UIView *)swipeHeaderBar {
[_swipeHeaderBar removeFromSuperview];
[self addSubview:swipeHeaderBar];

_swipeHeaderBar = swipeHeaderBar;
_swipeHeaderBar.y += _swipeHeaderTopInset;
_barInset = _swipeHeaderBar.bounds.size.height;
_swipeHeaderBar = swipeHeaderBar;
_swipeHeaderBar.st_y += _swipeHeaderTopInset;
_barInset = _swipeHeaderBar.bounds.size.height;

[self reloadData];
[self layoutIfNeeded];
Expand All @@ -199,10 +199,10 @@ - (void)setSwipeHeaderBar:(UIView *)swipeHeaderBar {

- (void)setSwipeHeaderTopInset:(CGFloat)swipeHeaderTopInset {
if (_swipeHeaderView) {
_swipeHeaderView.y += (swipeHeaderTopInset - _swipeHeaderTopInset);
_swipeHeaderView.st_y += (swipeHeaderTopInset - _swipeHeaderTopInset);
}
if (_swipeHeaderBar) {
_swipeHeaderBar.y += (swipeHeaderTopInset - _swipeHeaderTopInset);
_swipeHeaderBar.st_y += (swipeHeaderTopInset - _swipeHeaderTopInset);
}
_swipeHeaderTopInset = swipeHeaderTopInset;

Expand Down Expand Up @@ -316,19 +316,19 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell
UIView * headerView = [newSubView viewWithTag:666];
if (nil == headerView) {
headerView = [[UIView alloc]init];
headerView.width = newSubView.width;
headerView.st_width = newSubView.st_width;
headerView.tag = 666;
}
BOOL setHeaderHeight = [objc_getAssociatedObject(newSubView, SwipeTableViewItemTopInsetKey) boolValue];
if (!setHeaderHeight) {
headerView.height += headerHeight;
headerView.st_height += headerHeight;
objc_setAssociatedObject(newSubView, SwipeTableViewItemTopInsetKey, @(YES), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}else {
// update
CGFloat deltHeaderHeight = headerHeight - headerView.height;
headerView.height += deltHeaderHeight;
CGFloat deltHeaderHeight = headerHeight - headerView.st_height;
headerView.st_height += deltHeaderHeight;
}
contentInset.top = headerView.height + _swipeHeaderTopInset;
contentInset.top = headerView.st_height + _swipeHeaderTopInset;
newSubView.scrollIndicatorInsets = contentInset;
newSubView.headerView = headerView;

Expand Down Expand Up @@ -459,9 +459,9 @@ - (void)adjustItemViewContentOffset:(UIScrollView *)itemView atIndex:(NSInteger)
- (void)adjustItemViewContentSize:(UIScrollView *)itemView atIndex:(NSInteger)index {
// get the min required height of contentSize
#if !defined(ST_PULLTOREFRESH_HEADER_HEIGHT)
CGFloat minRequireHeight = itemView.height - (_swipeHeaderTopInset + _barInset);
CGFloat minRequireHeight = itemView.st_height - (_swipeHeaderTopInset + _barInset);
#else
CGFloat minRequireHeight = itemView.height - _swipeHeaderTopInset + _headerInset;
CGFloat minRequireHeight = itemView.st_height - _swipeHeaderTopInset + _headerInset;
#endif
// 修正contentInset的bottom的影响
minRequireHeight -= itemView.contentInset.bottom;
Expand Down Expand Up @@ -494,36 +494,36 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
return;
}
if (!_swipeHeaderBarScrollDisabled) {
CGFloat newOffsetY = [change[NSKeyValueChangeNewKey] CGPointValue].y;
CGFloat newOffsetY = [change[NSKeyValueChangeNewKey] CGPointValue].y;
#if !defined(ST_PULLTOREFRESH_HEADER_HEIGHT)
CGFloat topMarginOffset = _swipeHeaderTopInset + _barInset;
CGFloat topMarginOffset = _swipeHeaderTopInset + _barInset;
// stick the bar
if (newOffsetY < - topMarginOffset) {
if (_swipeHeaderBar) {
_swipeHeaderBar.bottom = - newOffsetY;
_swipeHeaderView.bottom = _swipeHeaderBar.top;
_swipeHeaderBar.st_bottom = - newOffsetY;
_swipeHeaderView.st_bottom = _swipeHeaderBar.st_top;
}else {
_swipeHeaderView.bottom = - newOffsetY;
_swipeHeaderView.st_bottom = - newOffsetY;
}
}else {
_swipeHeaderBar.bottom = topMarginOffset;
_swipeHeaderBar.st_bottom = topMarginOffset;
// 'fmax' is used to fix the bug below iOS8.3 : the position of the bar will not correct when the swipeHeaderView is outside of the screen.
_swipeHeaderView.bottom = fmax(- (newOffsetY + _barInset), 0);
_swipeHeaderView.st_bottom = fmax(- (newOffsetY + _barInset), 0);
}
#else
CGFloat topMarginOffset = _headerInset - _swipeHeaderTopInset;
CGFloat topMarginOffset = _headerInset - _swipeHeaderTopInset;
// stick the bar
if (newOffsetY < topMarginOffset) {
if (_swipeHeaderView) {
_swipeHeaderView.top = - newOffsetY;
_swipeHeaderBar.top = _swipeHeaderView.bottom;
_swipeHeaderView.st_top = - newOffsetY;
_swipeHeaderBar.st_top = _swipeHeaderView.st_bottom;
}else {
_swipeHeaderBar.top = - newOffsetY;
_swipeHeaderBar.st_top = - newOffsetY;
}
}else {
_swipeHeaderBar.top = _swipeHeaderTopInset;
_swipeHeaderBar.st_top = _swipeHeaderTopInset;
// 'fmax' is used to fix the bug below iOS8.3 : the position of the bar will not correct when the swipeHeaderView is outside of the screen.
_swipeHeaderView.top = fmax(- newOffsetY, - _headerInset);
_swipeHeaderView.st_top = fmax(- newOffsetY, - _headerInset);
}
#endif
}
Expand Down Expand Up @@ -620,7 +620,7 @@ - (void)headerViewDidFrameChanged:(STHeaderView *)headerView {
#else
CGFloat offsetY = - headerView.frame.origin.y;
#endif
_swipeHeaderBar.top = fmax(_swipeHeaderTopInset, headerView.bottom);
_swipeHeaderBar.st_top = fmax(_swipeHeaderTopInset, headerView.st_bottom);

_contentOffsetKVODisabled = YES;
CGPoint contentOffset = self.currentItemView.contentOffset;
Expand Down Expand Up @@ -649,8 +649,12 @@ - (void)headerView:(STHeaderView *)headerView didPan:(UIPanGestureRecognizer *)p
}
[headerView endDecelerating];
if (pan.state == UIGestureRecognizerStateEnded) {
// remove the saved contentOffset, avoid to reset the offset with saved contentOffset when pull to refresh
[_contentOffsetQuene removeObjectForKey:@(self.currentItemIndex)];

// call KVO to enable the pull-to-refresh
CGPoint contentOffset = self.currentItemView.contentOffset;
self.currentItemView.contentOffset = contentOffset; // call KVO to enable the pull-to-refresh
self.currentItemView.contentOffset = contentOffset;
}
}
}
Expand All @@ -660,7 +664,7 @@ - (void)headerView:(STHeaderView *)headerView didPan:(UIPanGestureRecognizer *)p
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

CGFloat offsetX = scrollView.contentOffset.x;
NSInteger currentItemIndex = offsetX/scrollView.width + 0.5;
NSInteger currentItemIndex = offsetX/scrollView.st_width + 0.5;

if (currentItemIndex != _currentItemIndex) {
if (_switchPageWithoutAnimation) {
Expand Down
22 changes: 11 additions & 11 deletions SwipeTableView/SwipeTableView/UIView+STFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@

@interface UIView (STFrame)

@property (nonatomic, assign) CGFloat x;
@property (nonatomic, assign) CGFloat y;
@property (nonatomic, assign) CGFloat width;
@property (nonatomic, assign) CGFloat height;
@property (nonatomic, assign) CGFloat centerX;
@property (nonatomic, assign) CGFloat centerY;
@property (nonatomic, assign) CGSize size;
@property (nonatomic, assign) CGFloat top;
@property (nonatomic, assign) CGFloat bottom;
@property (nonatomic, assign) CGFloat left;
@property (nonatomic, assign) CGFloat right;
@property (nonatomic, assign) CGFloat st_x;
@property (nonatomic, assign) CGFloat st_y;
@property (nonatomic, assign) CGFloat st_width;
@property (nonatomic, assign) CGFloat st_height;
@property (nonatomic, assign) CGFloat st_centerX;
@property (nonatomic, assign) CGFloat st_centerY;
@property (nonatomic, assign) CGSize st_size;
@property (nonatomic, assign) CGFloat st_top;
@property (nonatomic, assign) CGFloat st_bottom;
@property (nonatomic, assign) CGFloat st_left;
@property (nonatomic, assign) CGFloat st_right;

@end
64 changes: 33 additions & 31 deletions SwipeTableView/SwipeTableView/UIView+STFrame.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,106 +10,108 @@

@implementation UIView (Frame)

-(CGFloat)x {
-(CGFloat)st_x {
return self.frame.origin.x;
}

-(void)setX:(CGFloat)x {
-(void)setSt_x:(CGFloat)x {
CGRect rect = self.frame;
rect.origin.x = x;
self.frame = rect;
}

-(CGFloat)y {
-(CGFloat)st_y {
return self.frame.origin.y;
}

-(void)setY:(CGFloat)y {
-(void)setSt_y:(CGFloat)y {
CGRect rect = self.frame;
rect.origin.y = y;
self.frame = rect;
}

-(CGFloat)width {
-(CGFloat)st_width {
return self.frame.size.width;
}

-(void)setWidth:(CGFloat)width {
-(void)setSt_width:(CGFloat)width {
CGRect rect = self.frame;
rect.size.width = width;
self.frame = rect;
}

-(CGFloat)height {
-(CGFloat)st_height {
return self.frame.size.height;
}

-(void)setHeight:(CGFloat)height {
-(void)setSt_height:(CGFloat)height {
CGRect rect = self.frame;
rect.size.height = height;
self.frame = rect;
}

-(CGFloat)centerX {
-(CGFloat)st_centerX {
return self.center.x;
}

-(void)setCenterX:(CGFloat)centerX {
-(void)setSt_centerX:(CGFloat)centerX {
CGPoint center = self.center;
center.x = centerX;
self.center = center;
}

-(CGFloat)centerY {
-(CGFloat)st_centerY {
return self.center.y;
}

-(void)setCenterY:(CGFloat)centerY {
-(void)setSt_centerY:(CGFloat)centerY {
CGPoint center = self.center;
center.y = centerY;
self.center = center;
}

- (void)setSize:(CGSize)size {
CGRect frame = self.frame;
frame.size = size;
self.frame = frame;
}

- (CGSize)size {
- (CGSize)st_size {
return self.frame.size;
}

- (void)setTop:(CGFloat)t {
self.frame = CGRectMake(self.left, t, self.width, self.height);
- (void)setSt_size:(CGSize)size {
CGRect frame = self.frame;
frame.size = size;
self.frame = frame;
}

- (CGFloat)top {
- (CGFloat)st_top {
return self.frame.origin.y;
}

- (void)setBottom:(CGFloat)b {
self.frame = CGRectMake(self.left, b - self.height, self.width, self.height);
- (void)setSt_top:(CGFloat)t {
self.frame = CGRectMake(self.st_left, t, self.st_width, self.st_height);
}

- (CGFloat)bottom {
- (CGFloat)st_bottom {
return self.frame.origin.y + self.frame.size.height;
}

- (void)setLeft:(CGFloat)l {
self.frame = CGRectMake(l, self.top, self.width, self.height);
- (void)setSt_bottom:(CGFloat)b {
self.frame = CGRectMake(self.st_left, b - self.st_height, self.st_width, self.st_height);
}

- (CGFloat)left {
- (CGFloat)st_left {
return self.frame.origin.x;
}

- (void)setRight:(CGFloat)r {
self.frame = CGRectMake(r - self.width, self.top, self.width, self.height);
- (void)setSt_left:(CGFloat)l {
self.frame = CGRectMake(l, self.st_top, self.st_width, self.st_height);
}

- (CGFloat)right {
- (CGFloat)st_right {
return self.frame.origin.x + self.frame.size.width;
}

- (void)setSt_right:(CGFloat)r {
self.frame = CGRectMake(r - self.st_width, self.st_top, self.st_width, self.st_height);
}



@end
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ - (void)viewDidLoad {

self.view.backgroundColor = [UIColor blackColor];
self.imageView = [[UIImageView alloc]init];
_imageView.width = [UIScreen mainScreen].bounds.size.width;
_imageView.st_width = [UIScreen mainScreen].bounds.size.width;
_imageView.userInteractionEnabled = YES;
[self.view addSubview:_imageView];

Expand Down

This file was deleted.

Loading

0 comments on commit bfb29e9

Please sign in to comment.