我在Objective C中创建了一个应用程序。我想实现一些功能,以在外部显示器上显示屏幕的选定内容区域。例如,我总共有10个屏幕,我想显示4个屏幕,不想显示整个屏幕,只想在外部显示器中显示选定的视图和屏幕区域。
我已经对此进行了研究,发现了一个tutorial,但是该教程提供了快速的语言,我想用客观的c语言来实现。
答案 0 :(得分:1)
Objective C代码中的Swift教程:
#import "ViewController.h"
#import "ExternalScreenViewController.h"
@interface ViewController ()
{
UIWindow *externalWindow;
UIWebView *webView;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
webView = [[UIWebView alloc] init];
[self setupScreenNotifications];
NSURL *url = [NSURL URLWithString:@"http://www.spazstik-software.com"];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
[webView loadRequest:req];
if ([[UIScreen screens] count] > 1) {
[self setupExternalScreen:[UIScreen screens][1]];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)setupScreenNotifications {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(externalScreenDidConnect:) name:UIScreenDidConnectNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(externalScreenDidDisconnect:) name:UIScreenDidDisconnectNotification object:nil];
}
-(void)externalScreenDidConnect:(NSNotification *)notification {
UIScreen *screen = (UIScreen *)[notification object];
if (screen != nil) {
[self setupExternalScreen:screen];
}
}
-(void)externalScreenDidDisconnect:(NSNotification *)notification {
id obj = [notification object];
if (obj != nil) {
[self teardownExternalScreen];
}
}
-(void)setupExternalScreen:(UIScreen *)screen {
ExternalScreenViewController *vc = [[self storyboard] instantiateViewControllerWithIdentifier:@"ExternalScreen"];
externalWindow = [[UIWindow alloc]initWithFrame:screen.bounds];
externalWindow.rootViewController = vc;
externalWindow.screen = screen;
externalWindow.hidden = false;
}
-(void)teardownExternalScreen {
if (externalWindow != nil) {
externalWindow.hidden = true;
externalWindow = nil;
}
}
@end