VLCAboutViewController.m 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*****************************************************************************
  2. * VLC for iOS
  3. *****************************************************************************
  4. * Copyright (c) 2015 VideoLAN. All rights reserved.
  5. * $Id$
  6. *
  7. * Authors: Felix Paul Kühne <fkuehne # videolan.org>
  8. *
  9. * Refer to the COPYING file of the official project for license.
  10. *****************************************************************************/
  11. #import "VLCAboutViewController.h"
  12. @interface VLCAboutViewController ()
  13. {
  14. CADisplayLink *displayLink;
  15. NSTimer *startAnimationTimer;
  16. }
  17. @end
  18. @implementation VLCAboutViewController
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. NSBundle *mainBundle = [NSBundle mainBundle];
  22. self.versionLabel.text = [[NSString stringWithFormat:NSLocalizedString(@"VERSION_FORMAT", nil), [mainBundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"]] stringByAppendingFormat:@" (%@)", [mainBundle objectForInfoDictionaryKey:@"CFBundleVersion"]];
  23. self.basedOnLabel.text = [[NSString stringWithFormat:NSLocalizedString(@"BASED_ON_FORMAT", nil),[[VLCLibrary sharedLibrary] version]] stringByReplacingOccurrencesOfString:@"<br />" withString:@" "];
  24. self.titleLabel.text = self.title;
  25. self.titleLabel.textColor = [UIColor colorWithWhite:0.5 alpha:1.];
  26. UITextView *textView = self.blablaTextView;
  27. textView.attributedText = [[NSAttributedString alloc] initWithData:[[NSString stringWithContentsOfFile:[[NSBundle mainBundle]
  28. pathForResource:@"About Contents" ofType:@"html"]
  29. encoding:NSUTF8StringEncoding
  30. error:nil]
  31. dataUsingEncoding:NSUTF8StringEncoding]
  32. options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
  33. NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)}
  34. documentAttributes:nil error:nil];
  35. textView.scrollEnabled = YES;
  36. textView.panGestureRecognizer.allowedTouchTypes = @[ @(UITouchTypeIndirect) ];
  37. [textView.panGestureRecognizer addTarget:self action:@selector(scrollViewPan:)];
  38. textView.userInteractionEnabled = YES;
  39. textView.showsVerticalScrollIndicator = YES;
  40. UITapGestureRecognizer *tapUpArrowRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(scrollToTop)];
  41. tapUpArrowRecognizer.allowedPressTypes = @[@(UIPressTypeUpArrow)];
  42. [textView addGestureRecognizer:tapUpArrowRecognizer];
  43. }
  44. - (void)viewDidAppear:(BOOL)animated
  45. {
  46. [super viewDidAppear:animated];
  47. [self startAnimationTimer];
  48. }
  49. - (void) viewDidDisappear:(BOOL)animated
  50. {
  51. [super viewDidDisappear:animated];
  52. [self stopAnimation];
  53. }
  54. - (UIView *)preferredFocusedView
  55. {
  56. return self.blablaTextView;
  57. }
  58. - (void)scrollToTop
  59. {
  60. [self stopAnimation];
  61. [self.blablaTextView setContentOffset:CGPointZero animated:YES];
  62. [self startAnimationTimer];
  63. }
  64. - (void)scrollViewPan:(UIPanGestureRecognizer *)recognizer
  65. {
  66. switch(recognizer.state) {
  67. case UIGestureRecognizerStateCancelled:
  68. case UIGestureRecognizerStateFailed:
  69. case UIGestureRecognizerStateEnded:
  70. [self startAnimationTimer];
  71. break;
  72. default:
  73. [self stopAnimation];
  74. break;
  75. }
  76. }
  77. - (void)startAnimationTimer
  78. {
  79. [startAnimationTimer invalidate];
  80. startAnimationTimer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(startAnimation) userInfo:nil repeats:NO];
  81. }
  82. - (void)stopAnimation
  83. {
  84. [startAnimationTimer invalidate];
  85. startAnimationTimer = nil;
  86. [displayLink invalidate];
  87. displayLink = nil;
  88. }
  89. - (void)startAnimation
  90. {
  91. [displayLink invalidate];
  92. displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(displayLinkTriggered:)];
  93. [displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
  94. }
  95. - (void)displayLinkTriggered:(CADisplayLink*)link
  96. {
  97. UIScrollView *scrollView = self.blablaTextView;
  98. CGFloat viewHeight = CGRectGetHeight(scrollView.frame);
  99. CGFloat maxOffsetY = scrollView.contentSize.height - viewHeight;
  100. CFTimeInterval secondsPerPage = 4.0;
  101. CGFloat offset = link.duration/secondsPerPage * viewHeight;
  102. CGFloat newYOffset = scrollView.contentOffset.y + offset;
  103. if (newYOffset > maxOffsetY+viewHeight) {
  104. scrollView.contentOffset = CGPointMake(0, -viewHeight);
  105. } else {
  106. scrollView.contentOffset = CGPointMake(0, newYOffset);
  107. }
  108. }
  109. @end