mirror of
https://github.com/SoPat712/YTLitePlus.git
synced 2025-08-21 18:48:45 -04:00
Allow other gestures
This commit is contained in:
@@ -542,9 +542,10 @@ BOOL isTabSelected = NO;
|
|||||||
}
|
}
|
||||||
%end
|
%end
|
||||||
|
|
||||||
@interface YTPlayerViewController (YTLitePlus)
|
@interface YTPlayerViewController (YTLitePlus) <UIGestureRecognizerDelegate>
|
||||||
// the long press gesture that will be created and added to the player view
|
// the long press gesture that will be created and added to the player view
|
||||||
@property (nonatomic, retain) UIPanGestureRecognizer *YTLitePlusPanGesture;
|
@property (nonatomic, retain) UIPanGestureRecognizer *YTLitePlusPanGesture;
|
||||||
|
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;
|
||||||
@end
|
@end
|
||||||
@interface YTWatchFullscreenViewController : YTMultiSizeViewController
|
@interface YTWatchFullscreenViewController : YTMultiSizeViewController
|
||||||
@end
|
@end
|
||||||
@@ -562,78 +563,80 @@ BOOL isTabSelected = NO;
|
|||||||
if (!playerViewController.YTLitePlusPanGesture) {
|
if (!playerViewController.YTLitePlusPanGesture) {
|
||||||
playerViewController.YTLitePlusPanGesture = [[UIPanGestureRecognizer alloc] initWithTarget:playerViewController
|
playerViewController.YTLitePlusPanGesture = [[UIPanGestureRecognizer alloc] initWithTarget:playerViewController
|
||||||
action:@selector(YTLitePlusHandlePanGesture:)];
|
action:@selector(YTLitePlusHandlePanGesture:)];
|
||||||
|
playerViewController.YTLitePlusPanGesture.delegate = playerViewController;
|
||||||
[playerViewController.playerView addGestureRecognizer:playerViewController.YTLitePlusPanGesture];
|
[playerViewController.playerView addGestureRecognizer:playerViewController.YTLitePlusPanGesture];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
%orig;
|
%orig;
|
||||||
}
|
}
|
||||||
%end
|
%end
|
||||||
|
|
||||||
%hook YTPlayerViewController
|
%hook YTPlayerViewController
|
||||||
// the pan gesture that will be created and added to the player view
|
// the pan gesture that will be created and added to the player view
|
||||||
%property (nonatomic, retain) UIPanGestureRecognizer *YTLitePlusPanGesture;
|
%property (nonatomic, retain) UIPanGestureRecognizer *YTLitePlusPanGesture;
|
||||||
%new
|
%new
|
||||||
- (void)YTLitePlusHandlePanGesture:(UIPanGestureRecognizer *)panGestureRecognizer {
|
- (void)YTLitePlusHandlePanGesture:(UIPanGestureRecognizer *)panGestureRecognizer {
|
||||||
static float initialVolume;
|
static float initialVolume;
|
||||||
|
static BOOL isHorizontalPan = NO;
|
||||||
|
|
||||||
if (panGestureRecognizer.state == UIGestureRecognizerStateBegan) {
|
if (panGestureRecognizer.state == UIGestureRecognizerStateBegan) {
|
||||||
// Store the initial volume at the beginning of the pan gesture
|
// Store the initial volume at the beginning of the pan gesture
|
||||||
initialVolume = [[AVAudioSession sharedInstance] outputVolume];
|
initialVolume = [[AVAudioSession sharedInstance] outputVolume];
|
||||||
|
// Reset the horizontal pan flag
|
||||||
|
isHorizontalPan = NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (panGestureRecognizer.state == UIGestureRecognizerStateChanged) {
|
if (panGestureRecognizer.state == UIGestureRecognizerStateChanged) {
|
||||||
// Calculate the horizontal translation
|
// Calculate the translation
|
||||||
CGPoint translation = [panGestureRecognizer translationInView:self.view];
|
CGPoint translation = [panGestureRecognizer translationInView:self.view];
|
||||||
|
|
||||||
|
// Determine if the gesture is predominantly horizontal
|
||||||
|
if (!isHorizontalPan) {
|
||||||
|
if (fabs(translation.x) > fabs(translation.y)) {
|
||||||
|
isHorizontalPan = YES;
|
||||||
|
} else {
|
||||||
|
// If vertical movement is greater, cancel the gesture recognizer
|
||||||
|
panGestureRecognizer.state = UIGestureRecognizerStateCancelled;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isHorizontalPan) {
|
||||||
float newVolume = initialVolume + (translation.x / 1000.0); // Adjust the divisor to control the sensitivity
|
float newVolume = initialVolume + (translation.x / 1000.0); // Adjust the divisor to control the sensitivity
|
||||||
|
|
||||||
// Clamp the volume between 0 and 1
|
// Clamp the volume between 0 and 1
|
||||||
newVolume = fmaxf(fminf(newVolume, 1.0), 0.0);
|
newVolume = fmaxf(fminf(newVolume, 1.0), 0.0);
|
||||||
|
|
||||||
/*
|
|
||||||
// Navigate to existing volume slider view
|
|
||||||
YTWatchViewController *watchViewController = (YTWatchViewController *)[self valueForKey:@"_parentViewController"];
|
|
||||||
YTWatchLayerViewController *watchLayerViewController = (YTWatchLayerViewController *)[watchViewController valueForKey:@"_watchLayerViewController"];
|
|
||||||
YTWatchFullscreenViewController *watchFullscreenViewController = (YTWatchFullscreenViewController *)[watchLayerViewController valueForKey:@"_fullscreenViewController"];
|
|
||||||
MPVolumeView *volumeView = (MPVolumeView *)[watchFullscreenViewController valueForKey:@"_hiddenVolumeView"];
|
|
||||||
|
|
||||||
// https://stackoverflow.com/questions/50737943/how-to-change-volume-programmatically-on-ios-11-4/50740074#50740074
|
// https://stackoverflow.com/questions/50737943/how-to-change-volume-programmatically-on-ios-11-4/50740074#50740074
|
||||||
UISlider *volumeViewSlider = nil;
|
|
||||||
for (UIView *view in volumeView.subviews) {
|
|
||||||
if ([view isKindOfClass:[UISlider class]]) {
|
|
||||||
volumeViewSlider = (UISlider *)view;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Get the controller from this view
|
|
||||||
MPVolumeController *volumeController = [volumeViewSlider valueForKey:@"volumeController"];
|
|
||||||
// Set the volume
|
|
||||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
||||||
volumeController.volumeValue = newVolume;
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
|
|
||||||
MPVolumeView *volumeView = [[MPVolumeView alloc] init];
|
MPVolumeView *volumeView = [[MPVolumeView alloc] init];
|
||||||
UISlider *volumeViewSlider = nil;
|
UISlider *volumeViewSlider = nil;
|
||||||
|
|
||||||
for (UIView *view in volumeView.subviews) {
|
for (UIView *view in volumeView.subviews) {
|
||||||
if ([view isKindOfClass:[UISlider class]]) {
|
if ([view isKindOfClass:[UISlider class]]) {
|
||||||
volumeViewSlider = (UISlider *)view;
|
volumeViewSlider = (UISlider *)view;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||||
volumeViewSlider.value = newVolume;
|
volumeViewSlider.value = newVolume;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (panGestureRecognizer.state == UIGestureRecognizerStateEnded) {
|
if (panGestureRecognizer.state == UIGestureRecognizerStateEnded) {
|
||||||
|
if (isHorizontalPan) {
|
||||||
// Haptic feedback
|
// Haptic feedback
|
||||||
UINotificationFeedbackGenerator *feedbackGenerator = [[UINotificationFeedbackGenerator alloc] init];
|
UINotificationFeedbackGenerator *feedbackGenerator = [[UINotificationFeedbackGenerator alloc] init];
|
||||||
[feedbackGenerator notificationOccurred:UINotificationFeedbackTypeSuccess];
|
[feedbackGenerator notificationOccurred:UINotificationFeedbackTypeSuccess];
|
||||||
feedbackGenerator = nil;
|
feedbackGenerator = nil;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// allow the pan gesture to be recognized simultaneously with other gestures
|
||||||
|
%new
|
||||||
|
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
%end
|
%end
|
||||||
%end
|
%end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user