Skip to content

Instantly share code, notes, and snippets.

@marutanm
Created June 23, 2010 14:20
Show Gist options
  • Save marutanm/449978 to your computer and use it in GitHub Desktop.
Save marutanm/449978 to your computer and use it in GitHub Desktop.
show UIPageControl only scrolling
#import <UIKit/UIKit.h>
@interface ScrollViewDelegate : UIView <UIScrollViewDelegate> {
UIPageControl *pageControl;
NSTimer *updateTimer;
}
- (void)switchStateHidden;
@end
#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