VLCAboutViewController.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. NSMutableAttributedString *aboutContents = [[NSMutableAttributedString alloc] initWithData:[[NSString stringWithContentsOfFile:[[NSBundle mainBundle]
  27. pathForResource:@"About Contents" ofType:@"html"]
  28. encoding:NSUTF8StringEncoding
  29. error:nil]
  30. dataUsingEncoding:NSUTF8StringEncoding]
  31. options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
  32. NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)}
  33. documentAttributes:nil error:nil];
  34. if ([UIScreen mainScreen].traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) {
  35. [aboutContents addAttribute:NSForegroundColorAttributeName value:[UIColor VLCLightTextColor] range:NSMakeRange(0., aboutContents.length)];
  36. }
  37. UITextView *textView = self.blablaTextView;
  38. textView.attributedText = aboutContents;
  39. textView.scrollEnabled = YES;
  40. textView.panGestureRecognizer.allowedTouchTypes = @[ @(UITouchTypeIndirect) ];
  41. [textView.panGestureRecognizer addTarget:self action:@selector(scrollViewPan:)];
  42. textView.userInteractionEnabled = YES;
  43. textView.showsVerticalScrollIndicator = YES;
  44. UITapGestureRecognizer *tapUpArrowRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(scrollToTop)];
  45. tapUpArrowRecognizer.allowedPressTypes = @[@(UIPressTypeUpArrow)];
  46. [textView addGestureRecognizer:tapUpArrowRecognizer];
  47. }
  48. - (void)viewDidAppear:(BOOL)animated
  49. {
  50. [super viewDidAppear:animated];
  51. [self startAnimationTimer];
  52. }
  53. - (void) viewDidDisappear:(BOOL)animated
  54. {
  55. [super viewDidDisappear:animated];
  56. [self stopAnimation];
  57. }
  58. - (NSArray<id<UIFocusEnvironment>> *)preferredFocusEnvironments {
  59. return @[self.blablaTextView];
  60. }
  61. - (void)scrollToTop
  62. {
  63. [self stopAnimation];
  64. [self.blablaTextView setContentOffset:CGPointZero animated:YES];
  65. [self startAnimationTimer];
  66. }
  67. - (void)scrollViewPan:(UIPanGestureRecognizer *)recognizer
  68. {
  69. switch(recognizer.state) {
  70. case UIGestureRecognizerStateCancelled:
  71. case UIGestureRecognizerStateFailed:
  72. case UIGestureRecognizerStateEnded:
  73. [self startAnimationTimer];
  74. break;
  75. default:
  76. [self stopAnimation];
  77. break;
  78. }
  79. }
  80. - (void)startAnimationTimer
  81. {
  82. [startAnimationTimer invalidate];
  83. startAnimationTimer = [NSTimer scheduledTimerWithTimeInterval:4.0 target:self selector:@selector(startAnimation) userInfo:nil repeats:NO];
  84. }
  85. - (void)stopAnimation
  86. {
  87. [startAnimationTimer invalidate];
  88. startAnimationTimer = nil;
  89. [displayLink invalidate];
  90. displayLink = nil;
  91. }
  92. - (void)startAnimation
  93. {
  94. [displayLink invalidate];
  95. displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(displayLinkTriggered:)];
  96. [displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
  97. }
  98. - (void)displayLinkTriggered:(CADisplayLink*)link
  99. {
  100. UIScrollView *scrollView = self.blablaTextView;
  101. CGFloat viewHeight = CGRectGetHeight(scrollView.frame);
  102. CGFloat maxOffsetY = scrollView.contentSize.height - viewHeight;
  103. CFTimeInterval secondsPerPage = 5.0;
  104. CGFloat offset = link.duration/secondsPerPage * viewHeight;
  105. CGFloat newYOffset = scrollView.contentOffset.y + offset;
  106. if (newYOffset > maxOffsetY+viewHeight) {
  107. scrollView.contentOffset = CGPointMake(0, -viewHeight);
  108. } else {
  109. scrollView.contentOffset = CGPointMake(0, newYOffset);
  110. }
  111. }
  112. @end