- modularized settings widgets for iPad

- navBar for settings menu
This commit is contained in:
TrueZhuangjia authored and TrueZhuanjia committed 2025-05-17 22:40:10 +08:00
1 parent 4edf1e2cf5
commit 561080568c
12 files changed
+1280 -671

No files matched your search

@@ -961,12 +961,16 @@ static NSMutableSet* hostList;
}
}
- (void)revealController:(SWRevealViewController *)revealController didMoveToPosition:(FrontViewPosition)position {
// If we moved back to the center position, we should save the settings
- (void)revealController:(SWRevealViewController *)revealController willMoveToPosition:(FrontViewPosition)position {
SettingsViewController* settingsViewController = (SettingsViewController*)[revealController rearViewController];
settingsViewController.mainFrameViewController = self;
// enable / disable widgets acoordingly: in streamview, disable, outside of streamview, enable.
if (@available(iOS 16.0, *)) {
revealController.disconnectButton.hidden = !self.settingsExpandedInStreamView;
} else {
revealController.disconnectButton.enabled = self.settingsExpandedInStreamView;
// Fallback on earlier versions
}
[settingsViewController.resolutionSelector setEnabled:!self.settingsExpandedInStreamView];
[settingsViewController.framerateSelector setEnabled:!self.settingsExpandedInStreamView];
[settingsViewController widget:settingsViewController.bitrateSlider setEnabled:!self.settingsExpandedInStreamView];
@@ -978,8 +982,14 @@ static NSMutableSet* hostList;
[settingsViewController.framePacingSelector setEnabled:!self.settingsExpandedInStreamView];
[settingsViewController.btMouseSelector setEnabled:!self.settingsExpandedInStreamView];
[settingsViewController.externalDisplayModeSelector setEnabled:!self.settingsExpandedInStreamView];
[settingsViewController.backToStreamingButton setEnabled:self.settingsExpandedInStreamView];
[settingsViewController.backToStreamingButton setEnabled:self.settingsExpandedInStreamView]; // will be deprecated soon
// [settingsViewController.unlockDisplayOrientationSelector setEnabled:!self.settingsExpandedInStreamView && [self isFullScreenRequired]];//need "requires fullscreen" enabled in the app bunddle to make runtime orientation limitation woring
}
- (void)revealController:(SWRevealViewController *)revealController didMoveToPosition:(FrontViewPosition)position {
// If we moved back to the center position, we should save the settings
SettingsViewController* settingsViewController = (SettingsViewController*)[revealController rearViewController];
settingsViewController.mainFrameViewController = self;
if (position == FrontViewPositionLeft) {
[settingsViewController saveSettings];
@@ -183,6 +183,8 @@ typedef NS_ENUM(NSInteger, SWRevealToggleAnimationType)
@interface SWRevealViewController : UIViewController
@property (nonatomic, strong) UINavigationBar *dockedNavBar;
- (void)setPrimaryViewController:(UIViewController*)viewController;
/* Basic API */
@@ -239,6 +241,8 @@ typedef NS_ENUM(NSInteger, SWRevealToggleAnimationType)
/* The following properties are provided for further customization, they are set to default values on initialization,
you do not generally have to set them */
@property (strong, nonatomic) UIBarButtonItem *disconnectButton;
// Defines how much of the rear or right view is shown, default is 260.
// Negative values indicate that the reveal width should be computed by substracting the full front view width,
// so the revealed frontView width is kept constant when bounds change as opposed to the rear or right width.
@@ -30,6 +30,7 @@
#import <QuartzCore/QuartzCore.h>
#import "SWRevealViewController.h"
#import "LocalizationHelper.h"
#import "DataManager.h"
@@ -59,6 +60,7 @@ static CGFloat statusBarAdjustment( UIView* view )
}
@property (nonatomic, readonly) UIView *rearView;
@property (nonatomic, strong) UIView *rearNavView;
@property (nonatomic, readonly) UIView *rightView;
@property (nonatomic, readonly) UIView *frontView;
@property (nonatomic, assign) BOOL disableLayout;
@@ -73,7 +75,9 @@ static CGFloat statusBarAdjustment( UIView* view )
@end
@implementation SWRevealView
@implementation SWRevealView{
}
static CGFloat scaledValue( CGFloat v1, CGFloat min2, CGFloat max2, CGFloat min1, CGFloat max1)
@@ -99,7 +103,10 @@ static CGFloat scaledValue( CGFloat v1, CGFloat min2, CGFloat max2, CGFloat min1
[self reloadShadow];
[self addSubview:_frontView];
[self setupRearNavView];
}
return self;
}
@@ -128,13 +135,39 @@ static CGFloat scaledValue( CGFloat v1, CGFloat min2, CGFloat max2, CGFloat min1
}
- (void)setupRearNavView {
// 初始化 rearNavView
_rearNavView = [[UIView alloc] init];
_rearNavView.translatesAutoresizingMaskIntoConstraints = NO;
_rearNavView.backgroundColor = [UIColor lightGrayColor]; // 设置背景色以便查看
// NSLog(@"_c.rearViewRevealWidth: %f", _c.rearViewRevealWidth);
// _rearNavView.frame = CGRectMake(0, 0, _c.rearViewRevealWidth, 100);
// 添加到主视图
// 设置约束 - 这里只是一个示例,你可以根据需要调整
[self insertSubview:_rearNavView belowSubview:_frontView];
CGFloat navBarHeight = [UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone ? UINavigationBarHeightIPhone : UINavigationBarHeightIPad;
[NSLayoutConstraint activateConstraints:@[
[_rearNavView.topAnchor constraintEqualToAnchor:self.topAnchor],
[_rearNavView.leadingAnchor constraintEqualToAnchor:self.leadingAnchor],
[_rearNavView.trailingAnchor constraintEqualToAnchor:self.trailingAnchor],
[_rearNavView.heightAnchor constraintEqualToConstant:navBarHeight]
// reserve height for navigation bar
]];
// [self setupNavigationBar];
}
- (void)prepareRearViewForPosition:(FrontViewPosition)newPosition
{
if ( _rearView == nil )
{
_rearView = [[UIView alloc] initWithFrame:self.bounds];
_rearView.autoresizingMask = /*UIViewAutoresizingFlexibleWidth|*/UIViewAutoresizingFlexibleHeight;
[self insertSubview:_rearView belowSubview:_frontView];
[self insertSubview:_rearView belowSubview:_rearNavView];
}
CGFloat xLocation = [self frontLocationForPosition:_c.frontViewPosition];
@@ -633,7 +666,8 @@ const int FrontViewPositionNone = 0xff;
_rearViewPosition = FrontViewPositionLeft;
_rightViewPosition = FrontViewPositionLeft;
_rearViewRevealWidth = 492.0f;
_rearViewRevealOverdraw = 60.0f;
// _rearViewRevealOverdraw = 60.0f;
_rearViewRevealOverdraw = 0.0f;
_rearViewRevealDisplacement = 40.0f;
_rightViewRevealWidth = 492.0f;
_rightViewRevealOverdraw = 60.0f;
@@ -701,6 +735,8 @@ const int FrontViewPositionNone = 0xff;
// create a custom content view for the controller
_contentView = [[SWRevealView alloc] initWithFrame:frame controller:self];
[self setupNavigationBar];
// set the content view to resize along with its superview
[_contentView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
@@ -754,6 +790,9 @@ const int FrontViewPositionNone = 0xff;
else return [self getCurrentOrientation]; // 90 Degree rotation not allowed in streaming or app view
}
- (void)viewDidLayoutSubviews{
// [self setupNavigationBarConstraints];
}
- (void)viewDidLoad{
@@ -786,6 +825,70 @@ const int FrontViewPositionNone = 0xff;
#pragma mark - Public methods and property accessors
- (void)setupNavigationBar {
// 创建导航栏
if (_dockedNavBar == nil) _dockedNavBar = [[UINavigationBar alloc] init];
_dockedNavBar.translatesAutoresizingMaskIntoConstraints = NO;
_dockedNavBar.userInteractionEnabled = YES;
// 创建导航项
UINavigationItem *navItem = [[UINavigationItem alloc] initWithTitle:[LocalizationHelper localizedStringForKey:@"Settings"]];
// Back Button
UIButton *customBackButton = [UIButton buttonWithType:UIButtonTypeSystem];
if (@available(iOS 13.0, *)) {
[customBackButton setImage:[UIImage systemImageNamed:@"chevron.left"] forState:UIControlStateNormal];
} else {
// Fallback on earlier versions
}
[customBackButton setTitle:[LocalizationHelper localizedStringForKey:@"Back"] forState:UIControlStateNormal];
customBackButton.titleLabel.font = [UIFont systemFontOfSize:19 weight:UIFontWeightRegular];
[customBackButton addTarget:self action:@selector(foldRearView) forControlEvents:UIControlEventTouchUpInside];
//customBackButton.contentEdgeInsets = UIEdgeInsetsMake(8, 8, 8, 8); // 增加点击区域
// customBackButton.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, -5);
UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithCustomView:customBackButton];
/*
UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithTitle:[LocalizationHelper localizedStringForKey:@"Back"]
style:UIBarButtonItemStylePlain
target:self
action:@selector(foldRearView)];
*/
navItem.leftBarButtonItem = backButtonItem;
_disconnectButton = [[UIBarButtonItem alloc] initWithTitle:[LocalizationHelper localizedStringForKey:@"Disconnect"]
style:UIBarButtonItemStylePlain
target:self
action:@selector(disconnectRemoteSession)];
navItem.rightBarButtonItem = _disconnectButton;
[_dockedNavBar setItems:@[navItem]];
_dockedNavBar.barTintColor = [UIColor darkGrayColor];
_dockedNavBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]};
[_contentView.rearNavView addSubview:_dockedNavBar];
// 设置导航栏约束
[NSLayoutConstraint activateConstraints:@[
[_dockedNavBar.topAnchor constraintEqualToAnchor:_contentView.rearNavView.topAnchor],
[_dockedNavBar.bottomAnchor constraintEqualToAnchor:_contentView.rearNavView.bottomAnchor],
[_dockedNavBar.leadingAnchor constraintEqualToAnchor:_contentView.rearNavView.leadingAnchor],
[_dockedNavBar.widthAnchor constraintEqualToConstant:_rearViewRevealWidth],
]];
}
- (void)foldRearView{
[self revealToggleAnimated:YES];
}
- (void)disconnectRemoteSession{
[[NSNotificationCenter defaultCenter] postNotificationName:@"SessionDisconnectedBySettingsMenuNotification" object:self];
[self foldRearView];
}
- (void)setFrontViewController:(UIViewController *)frontViewController
{
[self setFrontViewController:frontViewController animated:NO];
@@ -16,6 +16,38 @@
#import "CustomEdgeSlideGestureRecognizer.h"
@interface SettingsViewController : UIViewController
@property (strong, nonatomic) IBOutlet UINavigationBar *navigationBar;
@property (strong, nonatomic) IBOutlet UIStackView *resolutionStack;
@property (strong, nonatomic) IBOutlet UIStackView *fpsStack;
@property (strong, nonatomic) IBOutlet UIStackView *bitrateStack;
@property (strong, nonatomic) IBOutlet UIStackView *touchModeStack;
@property (strong, nonatomic) IBOutlet UIStackView *asyncTouchStack;
@property (strong, nonatomic) IBOutlet UIStackView *pointerVelocityDividerStack;
@property (strong, nonatomic) IBOutlet UIStackView *pointerVelocityFactorStack;
@property (strong, nonatomic) IBOutlet UIStackView *touchMoveEventIntervalStack;
@property (strong, nonatomic) IBOutlet UIStackView *mousePointerVelocityStack;
@property (strong, nonatomic) IBOutlet UIStackView *onScreenWidgetStack;
@property (strong, nonatomic) IBOutlet UIStackView *keyboardToggleFingerNumStack;
@property (strong, nonatomic) IBOutlet UIStackView *liftStreamViewForKeyboardStack;
@property (strong, nonatomic) IBOutlet UIStackView *showKeyboardToolbarStack;
@property (strong, nonatomic) IBOutlet UIStackView *slideToSettingsScreenEdgeStack;
@property (strong, nonatomic) IBOutlet UIStackView *slideToCmdToolScreenEdgeStack;
@property (strong, nonatomic) IBOutlet UIStackView *slideToSettingsDistanceStack;
@property (strong, nonatomic) IBOutlet UIStackView *optimizeSettingsStack;
@property (strong, nonatomic) IBOutlet UIStackView *multiControllerStack;
@property (strong, nonatomic) IBOutlet UIStackView *swapAbaxyStack;
@property (strong, nonatomic) IBOutlet UIStackView *audioOnPcStack;
@property (strong, nonatomic) IBOutlet UIStackView *codecStack;
@property (strong, nonatomic) IBOutlet UIStackView *yuv444Stack;
@property (strong, nonatomic) IBOutlet UIStackView *HdrStack;
@property (strong, nonatomic) IBOutlet UIStackView *framepacingStack;
@property (strong, nonatomic) IBOutlet UIStackView *reverseMouseWheelDirectionStack;
@property (strong, nonatomic) IBOutlet UIStackView *citrixX1MouseStack;
@property (strong, nonatomic) IBOutlet UIStackView *statsOverlayStack;
@property (strong, nonatomic) IBOutlet UIStackView *unlockDisplayOrientationStack;
@property (strong, nonatomic) IBOutlet UIStackView *externalDisplayModeStack;
@property (strong, nonatomic) IBOutlet UIStackView *localMousePointerModeStack;
@property (strong, nonatomic) IBOutlet UILabel *bitrateLabel;
@property (strong, nonatomic) IBOutlet UISlider *bitrateSlider;
@property (strong, nonatomic) IBOutlet UISegmentedControl *framerateSelector;
@@ -25,6 +25,7 @@
bool justEnteredSettingsViewDoNotOpenOscLayoutTool;
uint16_t oscLayoutFingers;
CustomEdgeSlideGestureRecognizer *slideToCloseSettingsViewRecognizer;
UIStackView *parentStack;
}
@dynamic overrideUserInterfaceStyle;
@@ -159,6 +160,7 @@ CGSize resolutionTable[RESOLUTION_TABLE_SIZE];
// Enumerate the scroll view's subviews looking for the
// highest view Y value to set our scroll view's content
// size.
for (UIView* view in self.scrollView.subviews) {
// UIScrollViews have 2 default child views
// which represent the horizontal and vertical scrolling
@@ -177,7 +179,7 @@ CGSize resolutionTable[RESOLUTION_TABLE_SIZE];
// Add a bit of padding so the view doesn't end right at the button of the display
self.scrollView.contentSize = CGSizeMake(self.scrollView.contentSize.width,
highestViewY + 20);
[self isIPhone] ? highestViewY + 20 : parentStack.frame.size.height + [self getStandardNavBarHeight] + 20);
}
// Adjust the subviews for the safe area on the iPhone X.
@@ -300,23 +302,13 @@ BOOL isCustomResolution(CGSize res) {
[[NSNotificationCenter defaultCenter] postNotificationName:@"SettingsViewClosedNotification" object:self]; // notify other view that settings view just closed
}
- (void)pushDownExistingWidgets{
// Calculate the height needed for the exit button
CGFloat exitButtonHeight = 50.0; // Adjust as needed
CGFloat topOffset = exitButtonHeight; // Space needed for the exit button
// Iterate through subviews of self.view and adjust their frames
for (UIView *subview in self.view.subviews) {
CGRect frame = subview.frame;
frame.origin.y += topOffset;
subview.frame = frame;
}
}
//deprecated
- (IBAction)exitButtonTapped:(id)sender {
[self->_mainFrameViewController simulateSettingsButtonPress];
[[NSNotificationCenter defaultCenter] postNotificationName:@"SessionDisconnectedBySettingsViewNotification" object:self];
[[NSNotificationCenter defaultCenter] postNotificationName:@"SessionDisconnectedBySettingsMenuNotification" object:self];
}
//deprecated
- (IBAction)backToStreamingButtonTapped:(id)sender {
[self simulateSettingsButtonPress];
}
@@ -340,9 +332,77 @@ BOOL isCustomResolution(CGSize res) {
[self simulateSettingsButtonPress];
}
- (BOOL)isIPhone {
return [UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone;
}
- (CGFloat)getStandardNavBarHeight{
return [self isIPhone] ? UINavigationBarHeightIPhone : UINavigationBarHeightIPad;
}
- (void)layoutWidgetes {
// [self.view addSubview:self.navigationBar];
self.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
// 可选:确保 scrollView 开启垂直滚动
self.scrollView.alwaysBounceVertical = YES;
parentStack = [[UIStackView alloc] init];
parentStack.axis = UILayoutConstraintAxisVertical;
parentStack.spacing = 13;
parentStack.translatesAutoresizingMaskIntoConstraints = NO;
[self.scrollView addSubview:parentStack];
[NSLayoutConstraint activateConstraints:@[
[parentStack.topAnchor constraintEqualToAnchor:self.scrollView.contentLayoutGuide.topAnchor constant: [self getStandardNavBarHeight] + 20],
[parentStack.bottomAnchor constraintEqualToAnchor:self.scrollView.contentLayoutGuide.bottomAnchor constant:-20],
[parentStack.leadingAnchor constraintEqualToAnchor:self.scrollView.contentLayoutGuide.leadingAnchor constant: 14],
[parentStack.trailingAnchor constraintEqualToAnchor:self.scrollView.contentLayoutGuide.trailingAnchor constant: -15],
[parentStack.widthAnchor constraintEqualToAnchor:self.scrollView.contentLayoutGuide.widthAnchor]
]];
[parentStack addArrangedSubview:self.resolutionStack];
// self.resolutionStack.hidden = YES;
[parentStack addArrangedSubview:self.fpsStack];
// self.fpsStack.hidden = YES;
[parentStack addArrangedSubview:self.bitrateStack];
// self.bitrateStack.hidden = YES;
[parentStack addArrangedSubview:self.touchModeStack];
[parentStack addArrangedSubview:self.asyncTouchStack];
[parentStack addArrangedSubview:self.pointerVelocityDividerStack];
[parentStack addArrangedSubview:self.pointerVelocityFactorStack];
[parentStack addArrangedSubview:self.touchMoveEventIntervalStack];
[parentStack addArrangedSubview:self.mousePointerVelocityStack];
[parentStack addArrangedSubview:self.onScreenWidgetStack];
[parentStack addArrangedSubview:self.keyboardToggleFingerNumStack];
[parentStack addArrangedSubview:self.liftStreamViewForKeyboardStack];
[parentStack addArrangedSubview:self.showKeyboardToolbarStack];
[parentStack addArrangedSubview:self.slideToSettingsScreenEdgeStack];
[parentStack addArrangedSubview:self.slideToCmdToolScreenEdgeStack];
[parentStack addArrangedSubview:self.slideToSettingsDistanceStack];
[parentStack addArrangedSubview:self.optimizeSettingsStack];
[parentStack addArrangedSubview:self.multiControllerStack];
[parentStack addArrangedSubview:self.swapAbaxyStack];
[parentStack addArrangedSubview:self.audioOnPcStack];
[parentStack addArrangedSubview:self.codecStack];
[parentStack addArrangedSubview:self.yuv444Stack];
[parentStack addArrangedSubview:self.HdrStack];
[parentStack addArrangedSubview:self.framepacingStack];
[parentStack addArrangedSubview:self.reverseMouseWheelDirectionStack];
[parentStack addArrangedSubview:self.citrixX1MouseStack];
[parentStack addArrangedSubview:self.statsOverlayStack];
[parentStack addArrangedSubview:self.unlockDisplayOrientationStack];
[parentStack addArrangedSubview:self.externalDisplayModeStack];
[parentStack addArrangedSubview:self.localMousePointerModeStack];
}
- (void)viewDidLoad {
//[self pushDownExistingWidgets];
//[self addExitButtonOnTop];
BOOL isIPad = ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad);
if(isIPad) [self layoutWidgetes]; // layout for ipad tmply
self->slideToCloseSettingsViewRecognizer = [[CustomEdgeSlideGestureRecognizer alloc] initWithTarget:self action:@selector(edgeSwiped)];
slideToCloseSettingsViewRecognizer.edges = UIRectEdgeLeft;
@@ -250,8 +250,8 @@
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(sessionDisconnectedBySettingView) //quit session when exit button is press in setting view during streaming
name:@"SessionDisconnectedBySettingsViewNotification"
selector:@selector(disconnectRemoteSession) //quit session when exit button is press in setting view during streaming
name:@"SessionDisconnectedBySettingsMenuNotification"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
@@ -741,7 +741,7 @@
[self expandSettingsView]; // expand settings view in other cases;
}
- (void)sessionDisconnectedBySettingView {
- (void)disconnectRemoteSession {
Log(LOG_I, @"Settings view disconnect the session in stream view");
self.mainFrameViewcontroller.settingsExpandedInStreamView = false; // reset this flag to false
[self returnToMainFrame];