From 68f21fa8e57a81f3a84c2472bf24d5c3afce3af3 Mon Sep 17 00:00:00 2001 From: TrueZhuanjia Date: Sat, 7 Jun 2025 18:18:41 +0800 Subject: [PATCH] ios 12 & 13 compatibility for moreButton of settings navBar --- Limelight/HostCardView.h | 2 +- Limelight/HostCardView.m | 23 ++----- .../HostCollectionViewController.m | 5 -- .../ViewControllers/SWRevealViewController.m | 68 +++++++++++-------- .../ViewControllers/SettingsViewController.m | 4 -- Moonlight.xcodeproj/project.pbxproj | 2 +- 6 files changed, 47 insertions(+), 57 deletions(-) diff --git a/Limelight/HostCardView.h b/Limelight/HostCardView.h index f9a3590a..a46aac1f 100644 --- a/Limelight/HostCardView.h +++ b/Limelight/HostCardView.h @@ -19,7 +19,7 @@ @end -@interface HostCardView : UIView +@interface HostCardView : UIView @property (nonatomic, assign) CGFloat sizeFactor; @property (nonatomic, readonly) CGSize size; @property (nonatomic, weak) id delegate; // Delegate property diff --git a/Limelight/HostCardView.m b/Limelight/HostCardView.m index 87c6f441..0b5558f8 100644 --- a/Limelight/HostCardView.m +++ b/Limelight/HostCardView.m @@ -60,17 +60,10 @@ static const float REFRESH_CYCLE = 2.0f; defaultBlue = [ThemeManager appPrimaryColor]; defaultGreen = [UIColor colorWithRed:52.0/255.0 green:199.0/255.0 blue:89.0/255.0 alpha:1.0]; // self.userIterfaceStyle = UIUserInterfaceStyleLight - if (@available(iOS 13.0, *)) { - UIContextMenuInteraction* longPressInteraction = [[UIContextMenuInteraction alloc] initWithDelegate:self]; - [self addInteraction:longPressInteraction]; - self.userInteractionEnabled = YES; - } - else - { - UILongPressGestureRecognizer* longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(hostCardLongPressed:view:)]; - [self addGestureRecognizer:longPressRecognizer]; - } + UILongPressGestureRecognizer* longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(hostCardLongPressed:)]; + [self addGestureRecognizer:longPressRecognizer]; + [self createBackgroundLayer]; [self setupUI]; } @@ -149,18 +142,14 @@ static const float REFRESH_CYCLE = 2.0f; } - -- (UIContextMenuConfiguration *)contextMenuInteraction:(UIContextMenuInteraction *)interaction - configurationForMenuAtLocation:(CGPoint)location API_AVAILABLE(ios(13.0)){ +- (void)hostCardLongPressed:(UILongPressGestureRecognizer* )gesture{ + if(gesture.state != UIGestureRecognizerStateBegan) return; longPressFired = true; if ([self.delegate respondsToSelector:@selector(hostCardLongPressed:view:)]) { [self.delegate hostCardLongPressed:_host view:self]; - } else NSLog(@"Delegate not set or does not respond to pairButtonTappedForHost:"); - return nil; + } else NSLog(@"Delegate not set or does not respond"); } - - - (void)resizeBySizeFactor:(CGFloat)factor{ [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; self.sizeFactor = factor; diff --git a/Limelight/ViewControllers/HostCollectionViewController.m b/Limelight/ViewControllers/HostCollectionViewController.m index 12603317..1165aa59 100644 --- a/Limelight/ViewControllers/HostCollectionViewController.m +++ b/Limelight/ViewControllers/HostCollectionViewController.m @@ -103,11 +103,6 @@ static const CGFloat cellOffsetY = 20; - (void)viewDidLoad { [super viewDidLoad]; [self.collectionView registerClass:[HostCell class] forCellWithReuseIdentifier:@"HostCell"]; - if (@available(iOS 13.0, *)) { - self.collectionView.backgroundColor = UIColor.systemBackgroundColor; - } else { - // Fallback on earlier versions - } self.collectionView.alwaysBounceVertical = NO; self.collectionView.showsVerticalScrollIndicator = NO; self.collectionView.backgroundColor = [ThemeManager appBackgroundColor]; diff --git a/Limelight/ViewControllers/SWRevealViewController.m b/Limelight/ViewControllers/SWRevealViewController.m index 3bc24832..72f03fc6 100755 --- a/Limelight/ViewControllers/SWRevealViewController.m +++ b/Limelight/ViewControllers/SWRevealViewController.m @@ -1009,7 +1009,7 @@ const int FrontViewPositionNone = 0xff; [_moreButton setImage:image]; _moreButton.imageInsets = UIEdgeInsetsMake(20, 0, 0, -10); } else { - [_moreButton setTitle:[LocalizationHelper localizedStringForKey:@"More"]]; + [_moreButton setTitle:[LocalizationHelper localizedStringForKey:@"Options"]]; } // more option button } @@ -1095,33 +1095,48 @@ const int FrontViewPositionNone = 0xff; } - (void)moreButtonTapped:(UIBarButtonItem *)sender { - if (@available(iOS 14.0, *)) { - - - } else { - UIMenuItem *item1 = [[UIMenuItem alloc] initWithTitle:@"操作1" action:@selector(favoriteSettingSelected)]; - UIMenuItem *item2 = [[UIMenuItem alloc] initWithTitle:@"操作2" action:@selector(allSettingsSelected)]; - - UIMenuController *menuController = [UIMenuController sharedMenuController]; - [menuController setMenuItems:@[item1, item2]]; - - UIView *targetView = [sender valueForKey:@"view"]; - [menuController showMenuFromView:targetView rect:targetView.bounds]; - - [self becomeFirstResponder]; + UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil + message:nil + preferredStyle:UIAlertControllerStyleActionSheet]; + UIAlertAction *favoritesAction = [UIAlertAction actionWithTitle:[LocalizationHelper localizedStringForKey:@"Favorite Settings"] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * _Nonnull action) { + [self favoriteSettingSelected]; + }]; + UIAlertAction *allSettingsAction = [UIAlertAction actionWithTitle:[LocalizationHelper localizedStringForKey:@"All Settings"] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * _Nonnull action) { + [self allSettingSelected]; + }]; + UIAlertAction *enterRemoveItemsAction = [UIAlertAction actionWithTitle:[LocalizationHelper localizedStringForKey:@"Remove Items"] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * _Nonnull action) { + [self removeSettingItemSelected]; + }]; + UIAlertAction *doneRemoveItemsAction = [UIAlertAction actionWithTitle:[LocalizationHelper localizedStringForKey:@"Done"] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * _Nonnull action) { + [self doneRemoveSettingItemSelected]; + }]; + + switch ([self getSettingsMenuMode]) { + case AllSettings: + [actionSheet addAction:favoritesAction];break; + case FavoriteSettings: + [actionSheet addAction:allSettingsAction]; + [actionSheet addAction:enterRemoveItemsAction];break; + case RemoveSettingItem: + [actionSheet addAction:doneRemoveItemsAction];break; + default: + break; } + actionSheet.popoverPresentationController.sourceView = _contentView.rearNavView; // center of the view; + actionSheet.popoverPresentationController.sourceRect = CGRectMake(_rearViewRevealWidth + _moreButton.imageInsets.right - _moreButton.image.size.width/2, _contentView.rearNavView.bounds.size.height+_contentView.safeAreaInsets.top, 1.0, 1.0); + [self presentViewController:actionSheet animated:NO completion:nil]; } -- (BOOL)canBecomeFirstResponder { - return YES; -} -- (BOOL)canPerformAction:(SEL)action withSender:(id)sender { - if (action == @selector(favoriteSettingSelected) || action == @selector(allSettingsSelected)) { - return YES; - } - return NO; -} + - (SettingsMenuMode)getSettingsMenuMode { if ([self.navBarMenuDelegate respondsToSelector:@selector(getSettingsMenuMode)]) { @@ -1151,11 +1166,6 @@ const int FrontViewPositionNone = 0xff; } else NSLog(@"Delegate not set or does not respond to switchToAllSettings:"); } - -- (void)allSettingsSelected { - NSLog(@"执行操作2"); -} - - (void)buttonsInStreaming{ _navItem.rightBarButtonItems = @[_disconnectButton, _moreButton]; } diff --git a/Limelight/ViewControllers/SettingsViewController.m b/Limelight/ViewControllers/SettingsViewController.m index aab2bdce..7a59c376 100644 --- a/Limelight/ViewControllers/SettingsViewController.m +++ b/Limelight/ViewControllers/SettingsViewController.m @@ -1758,10 +1758,6 @@ BOOL isCustomResolution(CGSize res) { for (UIView *subview in view.subviews) { if ([subview isKindOfClass:[UISlider class]]) { UISlider *slider = (UISlider *)subview; - if (@available(iOS 13.0, *)) { - } else { - // Fallback on earlier versions - } slider.tintColor = [ThemeManager appSecondaryColor]; } diff --git a/Moonlight.xcodeproj/project.pbxproj b/Moonlight.xcodeproj/project.pbxproj index 53df7a7b..0e8cdae6 100644 --- a/Moonlight.xcodeproj/project.pbxproj +++ b/Moonlight.xcodeproj/project.pbxproj @@ -1112,7 +1112,7 @@ INFOPLIST_FILE = "Limelight/Limelight-Info.plist"; INFOPLIST_KEY_CFBundleDisplayName = MoonlightZWM; INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.games"; - IPHONEOS_DEPLOYMENT_TARGET = 13.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks",