makeKeyAndVisible

本文深入探讨了iOS开发中用于管理窗口显示的便捷方法makeKeyAndVisible,解释其作用、可用性及与其他窗口管理方法的关系。

Makes the receiver the key window and makes that window visible.

- (void)makeKeyAndVisible

Discussion

This is a convenience method to make the receiver the main window and displays it in front of other windows. You can also hide and reveal a window using the inheritedhidden UIView property.

Availability
  • Available in iPhone OS 2.0 and later.

我不知道为什么,不过有人搜索makeKeyAndVisible方法。其实我这种懒人一般不会刨根问底,有些方法照打就好,那些白给的方法有些就别动就好了。

我们看看这个每个程序都有的方法吧:

[window makeKeyAndVisible];

由于iPhone是单窗口程序,所以也就只有这么一个Window对象,而且是UIWindow,不是NSWindow。而根据文档上所说:

“这个是便捷方法,去使被使用对象的主窗口显示到屏幕的最前端。你也可以使用hiddenUIView方法隐藏这个窗口”

所以基本上来说,对于编程者的区别仅仅在于在其前添加代码,或在其后添加代码。



给我底层改: import UIKit import Network @UIApplicationMain class EnglishzidonghuaApp: UIResponder, UIApplicationDelegate { var window: UIWindow? func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { window = UIWindow(frame: UIScreen.main.bounds) window?.rootViewController = ViewController() window?.makeKeyAndVisible() return true } } class ViewController: UIViewController { var listener: NWListener? override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .white startTCPListener() } func startTCPListener() { listener = try? NWListener(using: .tcp, on: 8080) listener?.newConnectionHandler = { conn in conn.start(queue: .main) self.receiveCommand(conn) } listener?.start(queue: .main) } func receiveCommand(_ connection: NWConnection) { connection.receive(minimumIncompleteLength: 1, maximumLength: 1024) { data, _, isComplete, _ in if let data = data, let cmd = String(data: data, encoding: .utf8) { if cmd.contains("swipe") { self.performSystemSwipe() } } if !isComplete { self.receiveCommand(connection) } } } func performSystemSwipe() { let screenWidth = UIScreen.main.bounds.width let screenHeight = UIScreen.main.bounds.height let start = CGPoint(x: screenWidth/2, y: screenHeight-50) let end = CGPoint(x: screenWidth/2, y: 50) if let handle = dlopen("/System/Library/PrivateFrameworks/GSEvent.framework/GSEvent", RTLD_NOW) { if let symCreate = dlsym(handle, "GSEventCreateSwipe") { typealias SwipeFunc = @convention(c) (CGPoint, CGPoint, Double) -> UnsafeMutableRawPointer? let swipeFunc = unsafeBitCast(symCreate, to: SwipeFunc.self) let event = swipeFunc(start, end, 0.3) if let symSend = dlsym(handle, "GSEventSend") { typealias SendFunc = @convention(c) (UnsafeMutableRawPointer?) -> Void let sendFunc = unsafeBitCast(symSend, to: SendFunc.self) sendFunc(event) } if let symRelease = dlsym(handle, "CFRelease") { typealias ReleaseFunc = @convention(c) (UnsafeMutableRawPointer?) -> Void let releaseFunc = unsafeBitCast(symRelease, to: ReleaseFunc.self) releaseFunc(event) } } dlclose(handle) } } } 排除 WDA、排除 Python、排除快捷指令,不越狱。 只能无线,通过局域网。 Windows → iPhone 通过命令窗口,实现真实系统级手势上滑操作(APP 外部滑动)。 调用底层定义的手势,不通过快捷指令。 不可能?绝对能实现,我看见过大神操作过。 我看过大神实现的是直接执行上划。 调用私有 API,实现系统级上滑操作。 利用私有 API,内部测试可调用系统事件。 真实在第三方软件上划操作。 允许后台运行,接收到window的上划命令后自动在打开的第三方软件执行上划操作 在非越狱 iPhone 上,通过局域网接收 Windows 发来的命令,实现系统级上划手势,并能作用于第三方 App,后台运行。
09-18
#import <UIKit/UIKit.h> #import <ReactiveObjC/ReactiveObjC.h> NS_ASSUME_NONNULL_BEGIN #pragma mark - Model @interface StoryScene : NSObject @property (nonatomic, copy) NSString *sceneTitle; @property (nonatomic, copy) NSString *visualDescription; @property (nonatomic, strong) NSArray<NSString *> *symbolicElements; @end @implementation StoryScene @end @interface DigitalTool : NSObject @property (nonatomic, copy) NSString *toolName; @property (nonatomic, copy) NSString *usageDescription; @property (nonatomic, strong) NSArray<NSString *> *appliedScenes; @end @implementation DigitalTool @end @interface InteractionPlan : NSObject @property (nonatomic, copy) NSString *platform; @property (nonatomic, strong) NSArray<NSString *> *engagementMethods; @end @implementation InteractionPlan @end #pragma mark - ViewModel @interface StoryViewModel : NSObject @property (nonatomic, strong) NSArray<StoryScene *> *scenes; @property (nonatomic, strong) RACCommand *loadScenesCommand; @end @implementation StoryViewModel - (instancetype)init { self = [super init]; if (self) { @weakify(self); _loadScenesCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id _) { @strongify(self); return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) { [self fetchScenesFromService]; [subscriber sendCompleted]; return nil; }]; }]; } return self; } - (void)fetchScenesFromService { StoryScene *scene1 = [StoryScene new]; scene1.sceneTitle = @"黑暗中的微光"; scene1.visualDescription = @"黑白基调牢房,霉变米饭特写"; StoryScene *scene2 = [StoryScene new]; scene2.sceneTitle = @"铁窗下的课堂"; scene2.symbolicElements = @[@"树枝笔", @"棉灰墨", @"半截铅笔"]; _scenes = @[scene1, scene2]; } @end @interface ToolViewModel : NSObject @property (nonatomic, strong) NSArray<DigitalTool *> *tools; @property (nonatomic, strong) RACSubject *toolSelectedSubject; @end @implementation ToolViewModel - (instancetype)init { self = [super init]; if (self) { _toolSelectedSubject = [RACSubject subject]; [self setupTools]; } return self; } - (void)setupTools { DigitalTool *tool1 = [DigitalTool new]; tool1.toolName = @"PikaLabs"; tool1.usageDescription = @"水墨晕染风格动画"; DigitalTool *tool2 = [DigitalTool new]; tool2.toolName = @"Runway Gen-3"; tool2.usageDescription = @"动态分镜特效"; _tools = @[tool1, tool2]; } @end #pragma mark - View @interface SceneCell : UICollectionViewCell @property (nonatomic, strong) UILabel *titleLabel; @property (nonatomic, strong) UIImageView *symbolImageView; - (void)configureWithScene:(StoryScene *)scene; @end @implementation SceneCell - (void)configureWithScene:(StoryScene *)scene { _titleLabel.text = scene.sceneTitle; _symbolImageView.image = [UIImage imageNamed:scene.symbolicElements.firstObject]; } @end @interface MainViewController : UIViewController @property (nonatomic, strong) StoryViewModel *storyVM; @property (nonatomic, strong) ToolViewModel *toolVM; @property (nonatomic, strong) UICollectionView *collectionView; @end @implementation MainViewController - (void)viewDidLoad { [super viewDidLoad]; [self setupCollectionView]; [self bindViewModels]; } - (void)setupCollectionView { UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new]; _collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout]; [_collectionView registerClass:SceneCell.class forCellWithReuseIdentifier:@"SceneCell"]; [self.view addSubview:_collectionView]; } - (void)bindViewModels { @weakify(self); [[_storyVM.loadScenesCommand execute:nil] subscribeCompleted:^{ @strongify(self); [self.collectionView reloadData]; }]; [_toolVM.toolSelectedSubject subscribeNext:^(DigitalTool *tool) { NSLog(@"Selected tool: %@", tool.toolName); }]; } #pragma mark - UICollectionViewDataSource - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return _storyVM.scenes.count; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { SceneCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SceneCell" forIndexPath:indexPath]; [cell configureWithScene:_storyVM.scenes[indexPath.item]]; return cell; } @end #pragma mark - Coordinator @interface AppCoordinator : NSObject @property (nonatomic, strong) UINavigationController *navigationController; - (void)start; @end @implementation AppCoordinator - (void)start { MainViewController *mainVC = [MainViewController new]; mainVC.storyVM = [StoryViewModel new]; mainVC.toolVM = [ToolViewModel new]; _navigationController = [[UINavigationController alloc] initWithRootViewController:mainVC]; } @end #pragma mark - AppDelegate @interface AppDelegate : UIResponder <UIApplicationDelegate> @property (nonatomic, strong) UIWindow *window; @property (nonatomic, strong) AppCoordinator *coordinator; @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { _window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds]; _coordinator = [AppCoordinator new]; [_coordinator start]; _window.rootViewController = _coordinator.navigationController; [_window makeKeyAndVisible]; return YES; } @end NS_ASSUME_NONNULL_END
08-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值