|
@@ -13,11 +13,9 @@
|
|
|
|
|
|
@interface VLCAboutViewController ()
|
|
@interface VLCAboutViewController ()
|
|
{
|
|
{
|
|
- NSTimer *_scrollTimer;
|
|
|
|
- NSTimeInterval _startInterval;
|
|
|
|
- CGPoint _scrollPoint;
|
|
|
|
|
|
+ CADisplayLink *displayLink;
|
|
|
|
+ NSTimer *startAnimationTimer;
|
|
}
|
|
}
|
|
-
|
|
|
|
@end
|
|
@end
|
|
|
|
|
|
@implementation VLCAboutViewController
|
|
@implementation VLCAboutViewController
|
|
@@ -31,7 +29,8 @@
|
|
self.titleLabel.text = self.title;
|
|
self.titleLabel.text = self.title;
|
|
self.titleLabel.textColor = [UIColor colorWithWhite:0.5 alpha:1.];
|
|
self.titleLabel.textColor = [UIColor colorWithWhite:0.5 alpha:1.];
|
|
|
|
|
|
- self.blablaTextView.attributedText = [[NSAttributedString alloc] initWithData:[[NSString stringWithContentsOfFile:[[NSBundle mainBundle]
|
|
|
|
|
|
+ UITextView *textView = self.blablaTextView;
|
|
|
|
+ textView.attributedText = [[NSAttributedString alloc] initWithData:[[NSString stringWithContentsOfFile:[[NSBundle mainBundle]
|
|
pathForResource:@"About Contents" ofType:@"html"]
|
|
pathForResource:@"About Contents" ofType:@"html"]
|
|
encoding:NSUTF8StringEncoding
|
|
encoding:NSUTF8StringEncoding
|
|
error:nil]
|
|
error:nil]
|
|
@@ -39,55 +38,89 @@
|
|
options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
|
|
options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
|
|
NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)}
|
|
NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)}
|
|
documentAttributes:nil error:nil];
|
|
documentAttributes:nil error:nil];
|
|
- self.blablaTextView.scrollEnabled = YES;
|
|
|
|
|
|
+ textView.scrollEnabled = YES;
|
|
|
|
+ textView.panGestureRecognizer.allowedTouchTypes = @[ @(UITouchTypeIndirect) ];
|
|
|
|
+ [textView.panGestureRecognizer addTarget:self action:@selector(scrollViewPan:)];
|
|
|
|
+ textView.userInteractionEnabled = YES;
|
|
|
|
+ textView.showsVerticalScrollIndicator = YES;
|
|
|
|
+
|
|
|
|
+ UITapGestureRecognizer *tapUpArrowRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(scrollToTop)];
|
|
|
|
+ tapUpArrowRecognizer.allowedPressTypes = @[@(UIPressTypeUpArrow)];
|
|
|
|
+ [textView addGestureRecognizer:tapUpArrowRecognizer];
|
|
}
|
|
}
|
|
|
|
|
|
-- (void)viewWillAppear:(BOOL)animated
|
|
|
|
|
|
+- (void)viewDidAppear:(BOOL)animated
|
|
{
|
|
{
|
|
- [super viewWillAppear:animated];
|
|
|
|
-
|
|
|
|
- _scrollPoint = CGPointZero;
|
|
|
|
- if (!_scrollTimer) {
|
|
|
|
- _scrollTimer = [NSTimer scheduledTimerWithTimeInterval:1/6
|
|
|
|
- target:self
|
|
|
|
- selector:@selector(scrollABit:)
|
|
|
|
- userInfo:nil
|
|
|
|
- repeats:YES];
|
|
|
|
- }
|
|
|
|
|
|
+ [super viewDidAppear:animated];
|
|
|
|
+ [self startAnimationTimer];
|
|
|
|
+}
|
|
|
|
+- (void) viewDidDisappear:(BOOL)animated
|
|
|
|
+{
|
|
|
|
+ [super viewDidDisappear:animated];
|
|
|
|
+ [self stopAnimation];
|
|
}
|
|
}
|
|
|
|
|
|
-- (void)viewWillDisappear:(BOOL)animated
|
|
|
|
|
|
+- (UIView *)preferredFocusedView
|
|
{
|
|
{
|
|
- [super viewWillDisappear:animated];
|
|
|
|
|
|
+ return self.blablaTextView;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+- (void)scrollToTop
|
|
|
|
+{
|
|
|
|
+ [self stopAnimation];
|
|
|
|
+ [self.blablaTextView setContentOffset:CGPointZero animated:YES];
|
|
|
|
+ [self startAnimationTimer];
|
|
|
|
+}
|
|
|
|
|
|
- if (_scrollTimer) {
|
|
|
|
- [_scrollTimer invalidate];
|
|
|
|
- _scrollTimer = nil;
|
|
|
|
|
|
+- (void)scrollViewPan:(UIPanGestureRecognizer *)recognizer
|
|
|
|
+{
|
|
|
|
+ switch(recognizer.state) {
|
|
|
|
+ case UIGestureRecognizerStateCancelled:
|
|
|
|
+ case UIGestureRecognizerStateFailed:
|
|
|
|
+ case UIGestureRecognizerStateEnded:
|
|
|
|
+ [self startAnimationTimer];
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ [self stopAnimation];
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-- (void)resetScrolling
|
|
|
|
|
|
+- (void)startAnimationTimer
|
|
{
|
|
{
|
|
- _scrollPoint = CGPointZero;
|
|
|
|
- [self.blablaTextView setContentOffset:_scrollPoint animated:YES];
|
|
|
|
|
|
+ [startAnimationTimer invalidate];
|
|
|
|
+ startAnimationTimer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(startAnimation) userInfo:nil repeats:NO];
|
|
}
|
|
}
|
|
|
|
|
|
-- (void)scrollABit:(NSTimer *)timer
|
|
|
|
|
|
+- (void)stopAnimation
|
|
|
|
+{
|
|
|
|
+ [startAnimationTimer invalidate];
|
|
|
|
+ startAnimationTimer = nil;
|
|
|
|
+ [displayLink invalidate];
|
|
|
|
+ displayLink = nil;
|
|
|
|
+}
|
|
|
|
+- (void)startAnimation
|
|
{
|
|
{
|
|
- CGFloat maxHeight = self.blablaTextView.contentSize.height;
|
|
|
|
|
|
+ [displayLink invalidate];
|
|
|
|
+ displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(displayLinkTriggered:)];
|
|
|
|
+ [displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
|
|
|
|
+}
|
|
|
|
|
|
- if (!_startInterval) {
|
|
|
|
- _startInterval = [NSDate timeIntervalSinceReferenceDate] + 3.;
|
|
|
|
- }
|
|
|
|
|
|
+- (void)displayLinkTriggered:(CADisplayLink*)link
|
|
|
|
+{
|
|
|
|
+ UIScrollView *scrollView = self.blablaTextView;
|
|
|
|
+ CGFloat viewHeight = CGRectGetHeight(scrollView.frame);
|
|
|
|
+ CGFloat maxOffsetY = scrollView.contentSize.height - viewHeight;
|
|
|
|
+
|
|
|
|
+ CFTimeInterval secondsPerPage = 4.0;
|
|
|
|
+ CGFloat offset = link.duration/secondsPerPage * viewHeight;
|
|
|
|
|
|
- if ([NSDate timeIntervalSinceReferenceDate] >= _startInterval) {
|
|
|
|
- if (_scrollPoint.y > maxHeight) {
|
|
|
|
- [self resetScrolling];
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+ CGFloat newYOffset = scrollView.contentOffset.y + offset;
|
|
|
|
|
|
- _scrollPoint.y++;
|
|
|
|
- [self.blablaTextView setContentOffset:_scrollPoint animated:NO];
|
|
|
|
|
|
+ if (newYOffset > maxOffsetY+viewHeight) {
|
|
|
|
+ scrollView.contentOffset = CGPointMake(0, -viewHeight);
|
|
|
|
+ } else {
|
|
|
|
+ scrollView.contentOffset = CGPointMake(0, newYOffset);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|