Created
June 23, 2010 14:20
-
-
Save marutanm/449978 to your computer and use it in GitHub Desktop.
show UIPageControl only scrolling
This file contains 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
#import <UIKit/UIKit.h> | |
@interface ScrollViewDelegate : UIView <UIScrollViewDelegate> { | |
UIPageControl *pageControl; | |
NSTimer *updateTimer; | |
} | |
- (void)switchStateHidden; | |
@end |
This file contains 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
#import "ScrollViewDelegate.h" | |
@implementation ScrollViewDelegate | |
- (id)initWithFrame:(CGRect)frame { | |
self = [super initWithFrame:frame]; | |
pageControl = [[UIPageControl alloc] initWithFrame:frame]; | |
pageControl.userInteractionEnabled = NO; | |
[self addSubview:pageControl]; | |
// pageControl.alpha = 0.0; | |
return self; | |
} | |
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { | |
pageControl.alpha = 1.0; | |
if ([updateTimer isValid]) { | |
[updateTimer invalidate]; | |
} | |
} | |
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { | |
pageControl.currentPage = self.currentPage; | |
if (!updateTimer) { | |
updateTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:1.0] interval:0 target:self selector:@selector(switchStateHidden) userInfo:nil repeats:NO]; | |
} else if (![updateTimer isValid]) { | |
[updateTimer release]; | |
updateTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:1.0] interval:0 target:self selector:@selector(switchStateHidden) userInfo:nil repeats:NO]; | |
} | |
[[NSRunLoop mainRunLoop] addTimer:updateTimer forMode:NSRunLoopCommonModes]; | |
} | |
- (void)switchStateHidden { | |
[UIView animateWithDuration:0.5 animations:^{ pageControl.alpha = 0.0; }]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment