Last active
May 2, 2018 14:12
-
-
Save ShingoFukuyama/d296f7507b498000d34f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UIScrollView+Scrollabitily.h | |
// | |
// Created by FukuyamaShingo on 9/4/14. | |
// Copyright (c) 2014 FukuyamaShingo. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
@interface UIScrollView (Scrollabitily) | |
@property (nonatomic, assign, readonly) BOOL canScrollToTop; | |
@property (nonatomic, assign, readonly) BOOL canScrollToBottom; | |
@property (nonatomic, assign, readonly) BOOL canScrollToLeft; | |
@property (nonatomic, assign, readonly) BOOL canScrollToRight; | |
- (BOOL)canScrollWithPlayTop:(CGFloat)play; | |
- (BOOL)canScrollWithPlayBottom:(CGFloat)play; | |
- (BOOL)canScrollWithPlayLeft:(CGFloat)play; | |
- (BOOL)canScrollWithPlayRight:(CGFloat)play; | |
- (void)stopScrolling; | |
- (void)stopScrollingAnimated:(BOOL)animated; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UIScrollView+Scrollabitily.m | |
// | |
// Created by FukuyamaShingo on 9/4/14. | |
// Copyright (c) 2014 FukuyamaShingo. All rights reserved. | |
// | |
#import "UIScrollView+Scrollabitily.h" | |
@implementation UIScrollView (Scrollabitily) | |
#pragma mark - Check scrollability | |
- (BOOL)canScrollToTop | |
{ | |
return self.contentOffset.y > 0; | |
} | |
- (BOOL)canScrollToBottom | |
{ | |
CGFloat maxHeight = self.contentSize.height; | |
return (self.contentOffset.y + self.frame.size.height) < maxHeight; | |
} | |
- (BOOL)canScrollToLeft | |
{ | |
return self.contentOffset.x > 0; | |
} | |
- (BOOL)canScrollToRight | |
{ | |
CGFloat maxWidth = self.contentSize.width; | |
return (self.contentOffset.x + self.frame.size.width) < maxWidth; | |
} | |
- (BOOL)canScrollWithPlayTop:(CGFloat)play | |
{ | |
return self.contentOffset.y > play; | |
} | |
- (BOOL)canScrollWithPlayBottom:(CGFloat)play | |
{ | |
CGFloat maxHeight = self.contentSize.height; | |
return (self.contentOffset.y + self.frame.size.height) < (maxHeight - play); | |
} | |
- (BOOL)canScrollWithPlayLeft:(CGFloat)play | |
{ | |
return self.contentOffset.x > play; | |
} | |
- (BOOL)canScrollWithPlayRight:(CGFloat)play | |
{ | |
CGFloat maxWidth = self.contentSize.width; | |
return (self.contentOffset.x + self.frame.size.width) < (maxWidth - play); | |
} | |
#pragma mark - Affect scrolling | |
- (void)stopScrolling | |
{ | |
[self stopScrollingAnimated:NO]; | |
} | |
- (void)stopScrollingAnimated:(BOOL)animated | |
{ | |
[self setContentOffset:self.contentOffset animated:animated]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment