VLCAboutViewController.m 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. NSTimer *_scrollTimer;
  15. NSTimeInterval _startInterval;
  16. CGPoint _scrollPoint;
  17. }
  18. @end
  19. @implementation VLCAboutViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. NSBundle *mainBundle = [NSBundle mainBundle];
  23. self.versionLabel.text = [[NSString stringWithFormat:NSLocalizedString(@"VERSION_FORMAT", nil), [mainBundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"]] stringByAppendingFormat:@" (%@)", [mainBundle objectForInfoDictionaryKey:@"CFBundleVersion"]];
  24. self.basedOnLabel.text = [[NSString stringWithFormat:NSLocalizedString(@"BASED_ON_FORMAT", nil),[[VLCLibrary sharedLibrary] version]] stringByReplacingOccurrencesOfString:@"<br />" withString:@" "];
  25. self.titleLabel.text = self.title;
  26. self.titleLabel.textColor = [UIColor colorWithWhite:0.5 alpha:1.];
  27. self.blablaTextView.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. self.blablaTextView.scrollEnabled = YES;
  36. }
  37. - (void)viewWillAppear:(BOOL)animated
  38. {
  39. [super viewWillAppear:animated];
  40. _scrollPoint = CGPointZero;
  41. if (!_scrollTimer) {
  42. _scrollTimer = [NSTimer scheduledTimerWithTimeInterval:1/6
  43. target:self
  44. selector:@selector(scrollABit:)
  45. userInfo:nil
  46. repeats:YES];
  47. }
  48. }
  49. - (void)viewWillDisappear:(BOOL)animated
  50. {
  51. [super viewWillDisappear:animated];
  52. if (_scrollTimer) {
  53. [_scrollTimer invalidate];
  54. _scrollTimer = nil;
  55. }
  56. }
  57. - (void)resetScrolling
  58. {
  59. _scrollPoint = CGPointZero;
  60. [self.blablaTextView setContentOffset:_scrollPoint animated:YES];
  61. }
  62. - (void)scrollABit:(NSTimer *)timer
  63. {
  64. CGFloat maxHeight = self.blablaTextView.contentSize.height;
  65. if (!_startInterval) {
  66. _startInterval = [NSDate timeIntervalSinceReferenceDate] + 3.;
  67. }
  68. if ([NSDate timeIntervalSinceReferenceDate] >= _startInterval) {
  69. if (_scrollPoint.y > maxHeight) {
  70. [self resetScrolling];
  71. return;
  72. }
  73. _scrollPoint.y++;
  74. [self.blablaTextView setContentOffset:_scrollPoint animated:NO];
  75. }
  76. }
  77. @end