您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

204 行
7.4KB

  1. #define kBundlePath @"/Library/Application Support/AVLockBundle.bundle"
  2. @interface SBOrientationLockManager
  3. +(SBOrientationLockManager *)sharedInstance;
  4. -(bool)isUserLocked;
  5. -(void)lock;
  6. -(void)unlock;
  7. -(void)myIsUserLocked;
  8. @end
  9. @interface AVButton : UIView
  10. @end
  11. @interface AVTransportControlsView : UIView
  12. -(void)deviceOrientationDidChange;
  13. @property (assign, nonatomic) AVButton *skipBackButton;
  14. @property (assign, nonatomic) AVButton *skipForwardButton;
  15. @property (assign, nonatomic) AVButton *standardPlayPauseButton;
  16. @end
  17. @interface AVPlaybackControlsView
  18. @property (assign, nonatomic) AVTransportControlsView *transportControlsView;
  19. @end
  20. @interface AVPlayerViewControllerContentView
  21. @property (assign, nonatomic) AVPlaybackControlsView *playbackControlsView;
  22. @end
  23. @interface AVFullScreenViewController
  24. @property (assign, nonatomic) AVPlayerViewControllerContentView *contentView;
  25. @end
  26. extern "C" CFNotificationCenterRef CFNotificationCenterGetDistributedCenter(void);
  27. static UIButton *button = nil;
  28. static NSString *myObserver=@"anObserver";
  29. static void toggle(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo){
  30. if([[%c(SBOrientationLockManager) sharedInstance] isUserLocked]){
  31. [[%c(SBOrientationLockManager) sharedInstance] unlock];
  32. }else{
  33. [[%c(SBOrientationLockManager) sharedInstance] lock];
  34. }
  35. }
  36. static void lockButton(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo){
  37. NSBundle *bundle = [[[NSBundle alloc] initWithPath:kBundlePath] autorelease];
  38. NSString *imagePath = [bundle pathForResource:@"Locked@3x" ofType:@"png"];
  39. UIImage *img = [UIImage imageWithContentsOfFile:imagePath];
  40. [button setImage:img forState:UIControlStateNormal];
  41. [button setImage:img forState:UIControlStateHighlighted];
  42. [button setImage:img forState:UIControlStateSelected];
  43. }
  44. static void unlockButton(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo){
  45. NSBundle *bundle = [[[NSBundle alloc] initWithPath:kBundlePath] autorelease];
  46. NSString *imagePath = [bundle pathForResource:@"Unlocked@3x" ofType:@"png"];
  47. UIImage *img = [UIImage imageWithContentsOfFile:imagePath];
  48. [button setImage:img forState:UIControlStateNormal];
  49. [button setImage:img forState:UIControlStateHighlighted];
  50. [button setImage:img forState:UIControlStateSelected];
  51. }
  52. static void firstUpdate(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo){
  53. [[%c(SBOrientationLockManager) sharedInstance] myIsUserLocked];
  54. }
  55. %hook AVFullScreenViewController
  56. int test = 30;
  57. -(void)viewDidLayoutSubviews{
  58. %orig;
  59. if(test > 1){
  60. [self.contentView.playbackControlsView.transportControlsView deviceOrientationDidChange];
  61. test--;;
  62. }
  63. }
  64. -(void)viewDidDisappear:(bool)arg1{
  65. %orig;
  66. test = 10;
  67. }
  68. %end
  69. %hook SBOrientationLockManager
  70. -(SBOrientationLockManager*)init{
  71. self = %orig;
  72. CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
  73. (void*)myObserver,
  74. toggle,
  75. CFSTR("avlock.toggle"),
  76. NULL,
  77. CFNotificationSuspensionBehaviorDeliverImmediately);
  78. CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
  79. (void*)myObserver,
  80. firstUpdate,
  81. CFSTR("avlock.firstUpdate"),
  82. NULL,
  83. CFNotificationSuspensionBehaviorDeliverImmediately);
  84. return self;
  85. }
  86. %new
  87. -(void)myIsUserLocked{
  88. bool locked = [self isUserLocked];
  89. if(locked){
  90. CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("avlock.lockButton"), (void*)myObserver, NULL, true);
  91. }else{
  92. CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("avlock.unlockButton"), (void*)myObserver, NULL, true);
  93. }
  94. }
  95. -(void)unlock{
  96. %orig;
  97. CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("avlock.unlockButton"), (void*)myObserver, NULL, true);
  98. }
  99. -(void)lock{
  100. %orig;
  101. CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("avlock.lockButton"), (void*)myObserver, NULL, true);
  102. }
  103. %end
  104. %hook AVTransportControlsView
  105. -(AVTransportControlsView *)initWithFrame:(CGRect)frame{
  106. AVTransportControlsView *origself = %orig(frame);
  107. CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
  108. (void*)myObserver,
  109. lockButton,
  110. CFSTR("avlock.lockButton"),
  111. NULL,
  112. CFNotificationSuspensionBehaviorDeliverImmediately);
  113. CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
  114. (void*)myObserver,
  115. unlockButton,
  116. CFSTR("avlock.unlockButton"),
  117. NULL,
  118. CFNotificationSuspensionBehaviorDeliverImmediately);
  119. button = [UIButton buttonWithType:UIButtonTypeCustom];
  120. [button addTarget:self action:@selector(orientationButtonPressed) forControlEvents:UIControlEventTouchUpInside];
  121. CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("avlock.firstUpdate"), (void*)myObserver, NULL, true);
  122. button.contentMode = UIViewContentModeScaleAspectFit;
  123. button.imageEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10);
  124. [self addSubview:button];
  125. [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
  126. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange) name:UIDeviceOrientationDidChangeNotification object:nil];
  127. return origself;
  128. }
  129. -(void)dealloc{
  130. %orig;
  131. CFNotificationCenterRemoveObserver ( CFNotificationCenterGetDarwinNotifyCenter(), (void*)myObserver, NULL, NULL);
  132. }
  133. %new
  134. -(void)deviceOrientationDidChange{
  135. double delayInSeconds = 0.13;
  136. dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
  137. dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
  138. UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation;
  139. if (orientation == UIInterfaceOrientationLandscapeRight || orientation == UIInterfaceOrientationLandscapeLeft){
  140. CGPoint point = self.standardPlayPauseButton.frame.origin;
  141. point.x = (self.skipForwardButton.frame.origin.x - 40);
  142. [self.standardPlayPauseButton setFrame:CGRectMake(point.x, point.y, self.standardPlayPauseButton.frame.size.width, self.standardPlayPauseButton.frame.size.height)];
  143. point = self.skipBackButton.frame.origin;
  144. point.x = (self.standardPlayPauseButton.frame.origin.x - 40);
  145. [self.skipBackButton setFrame:CGRectMake(point.x, point.y, self.skipBackButton.frame.size.width, self.skipBackButton.frame.size.height)];
  146. [button setFrame:CGRectMake(self.standardPlayPauseButton.frame.origin.x-93.5, self.standardPlayPauseButton.frame.origin.y, 46, 46)];
  147. }
  148. else if(orientation == UIInterfaceOrientationPortrait){
  149. button.frame = CGRectMake((self.skipBackButton.frame.origin.x - 62), self.skipBackButton.frame.origin.y, 46, 46);
  150. }
  151. });
  152. }
  153. %new
  154. -(void)orientationButtonPressed{
  155. CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("avlock.toggle"), (void*)myObserver, NULL, true);
  156. }
  157. %end