ios 12 & 13 compatibility for moreButton of settings navBar

This commit is contained in:
TrueZhuanjia committed 2025-06-07 18:18:41 +08:00
1 parent d9dbb2bcee
commit 68f21fa8e5
6 files changed
+47 -57

No files matched your search

+1 -1
View File
@@ -19,7 +19,7 @@
@end @end
@interface HostCardView : UIView <UIContextMenuInteractionDelegate> @interface HostCardView : UIView
@property (nonatomic, assign) CGFloat sizeFactor; @property (nonatomic, assign) CGFloat sizeFactor;
@property (nonatomic, readonly) CGSize size; @property (nonatomic, readonly) CGSize size;
@property (nonatomic, weak) id<HostCardActionDelegate> delegate; // Delegate property @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]; defaultBlue = [ThemeManager appPrimaryColor];
defaultGreen = [UIColor colorWithRed:52.0/255.0 green:199.0/255.0 blue:89.0/255.0 alpha:1.0]; defaultGreen = [UIColor colorWithRed:52.0/255.0 green:199.0/255.0 blue:89.0/255.0 alpha:1.0];
// self.userIterfaceStyle = UIUserInterfaceStyleLight // 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 createBackgroundLayer];
[self setupUI]; [self setupUI];
} }
@@ -149,18 +142,14 @@ static const float REFRESH_CYCLE = 2.0f;
} }
- (void)hostCardLongPressed:(UILongPressGestureRecognizer* )gesture{
- (UIContextMenuConfiguration *)contextMenuInteraction:(UIContextMenuInteraction *)interaction if(gesture.state != UIGestureRecognizerStateBegan) return;
configurationForMenuAtLocation:(CGPoint)location API_AVAILABLE(ios(13.0)){
longPressFired = true; longPressFired = true;
if ([self.delegate respondsToSelector:@selector(hostCardLongPressed:view:)]) { if ([self.delegate respondsToSelector:@selector(hostCardLongPressed:view:)]) {
[self.delegate hostCardLongPressed:_host view:self]; [self.delegate hostCardLongPressed:_host view:self];
} else NSLog(@"Delegate not set or does not respond to pairButtonTappedForHost:"); } else NSLog(@"Delegate not set or does not respond");
return nil;
} }
- (void)resizeBySizeFactor:(CGFloat)factor{ - (void)resizeBySizeFactor:(CGFloat)factor{
[self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
self.sizeFactor = factor; self.sizeFactor = factor;
@@ -103,11 +103,6 @@ static const CGFloat cellOffsetY = 20;
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
[self.collectionView registerClass:[HostCell class] forCellWithReuseIdentifier:@"HostCell"]; [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.alwaysBounceVertical = NO;
self.collectionView.showsVerticalScrollIndicator = NO; self.collectionView.showsVerticalScrollIndicator = NO;
self.collectionView.backgroundColor = [ThemeManager appBackgroundColor]; self.collectionView.backgroundColor = [ThemeManager appBackgroundColor];
@@ -1009,7 +1009,7 @@ const int FrontViewPositionNone = 0xff;
[_moreButton setImage:image]; [_moreButton setImage:image];
_moreButton.imageInsets = UIEdgeInsetsMake(20, 0, 0, -10); _moreButton.imageInsets = UIEdgeInsetsMake(20, 0, 0, -10);
} else { } else {
[_moreButton setTitle:[LocalizationHelper localizedStringForKey:@"More"]]; [_moreButton setTitle:[LocalizationHelper localizedStringForKey:@"Options"]];
} }
// more option button // more option button
} }
@@ -1095,33 +1095,48 @@ const int FrontViewPositionNone = 0xff;
} }
- (void)moreButtonTapped:(UIBarButtonItem *)sender { - (void)moreButtonTapped:(UIBarButtonItem *)sender {
if (@available(iOS 14.0, *)) { UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
} else { UIAlertAction *favoritesAction = [UIAlertAction actionWithTitle:[LocalizationHelper localizedStringForKey:@"Favorite Settings"]
UIMenuItem *item1 = [[UIMenuItem alloc] initWithTitle:@"操作1" action:@selector(favoriteSettingSelected)]; style:UIAlertActionStyleDefault
UIMenuItem *item2 = [[UIMenuItem alloc] initWithTitle:@"操作2" action:@selector(allSettingsSelected)]; handler:^(UIAlertAction * _Nonnull action) {
[self favoriteSettingSelected];
UIMenuController *menuController = [UIMenuController sharedMenuController]; }];
[menuController setMenuItems:@[item1, item2]]; UIAlertAction *allSettingsAction = [UIAlertAction actionWithTitle:[LocalizationHelper localizedStringForKey:@"All Settings"]
style:UIAlertActionStyleDefault
UIView *targetView = [sender valueForKey:@"view"]; handler:^(UIAlertAction * _Nonnull action) {
[menuController showMenuFromView:targetView rect:targetView.bounds]; [self allSettingSelected];
}];
[self becomeFirstResponder]; 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 { - (SettingsMenuMode)getSettingsMenuMode {
if ([self.navBarMenuDelegate respondsToSelector:@selector(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:"); } else NSLog(@"Delegate not set or does not respond to switchToAllSettings:");
} }
- (void)allSettingsSelected {
NSLog(@"执行操作2");
}
- (void)buttonsInStreaming{ - (void)buttonsInStreaming{
_navItem.rightBarButtonItems = @[_disconnectButton, _moreButton]; _navItem.rightBarButtonItems = @[_disconnectButton, _moreButton];
} }
@@ -1758,10 +1758,6 @@ BOOL isCustomResolution(CGSize res) {
for (UIView *subview in view.subviews) { for (UIView *subview in view.subviews) {
if ([subview isKindOfClass:[UISlider class]]) { if ([subview isKindOfClass:[UISlider class]]) {
UISlider *slider = (UISlider *)subview; UISlider *slider = (UISlider *)subview;
if (@available(iOS 13.0, *)) {
} else {
// Fallback on earlier versions
}
slider.tintColor = [ThemeManager appSecondaryColor]; slider.tintColor = [ThemeManager appSecondaryColor];
} }
+1 -1
View File
@@ -1112,7 +1112,7 @@
INFOPLIST_FILE = "Limelight/Limelight-Info.plist"; INFOPLIST_FILE = "Limelight/Limelight-Info.plist";
INFOPLIST_KEY_CFBundleDisplayName = MoonlightZWM; INFOPLIST_KEY_CFBundleDisplayName = MoonlightZWM;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.games"; INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.games";
IPHONEOS_DEPLOYMENT_TARGET = 13.0; IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
"@executable_path/Frameworks", "@executable_path/Frameworks",