ios 12 & 13 compatibility for moreButton of settings navBar

This commit is contained in:
TrueZhuanjia
2025-06-07 18:18:41 +08:00
parent d9dbb2bcee
commit 68f21fa8e5
6 changed files with 47 additions and 57 deletions
+1 -1
View File
@@ -19,7 +19,7 @@
@end
@interface HostCardView : UIView <UIContextMenuInteractionDelegate>
@interface HostCardView : UIView
@property (nonatomic, assign) CGFloat sizeFactor;
@property (nonatomic, readonly) CGSize size;
@property (nonatomic, weak) id<HostCardActionDelegate> delegate; // Delegate property
+6 -17
View File
@@ -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;
@@ -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];
@@ -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];
}
@@ -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];
}
+1 -1
View File
@@ -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",