如果设备不支持镜像(原始iPad),我想在外部连接显示器上呈现独特内容,但如果是iPad 2,则想要使用屏幕镜像。现在,当我尝试按如下方式对其进行编码时:
if ([UIScreen instancesRespondToSelector:@selector(mirroredScreen)] && [[UIScreen mainScreen] mirroredScreen] == nil) {
// Mirroring not supported. Present unique content on external display
}
[[UIScreen mainScreen] mirroredScreen]
始终返回nil
。
我做错了吗?
答案 0 :(得分:10)
据我了解文档,如果您在实际是镜像屏幕的辅助屏幕上访问该属性,mirroredScreen
将引用主屏幕。如:
if ([[UIScreen screens] count] > 1) {
UIScreen *secondaryScreen = [[UIScreen screens] objectAtIndex:1];
NSLog(@"%@", secondaryScreen.mirroredScreen); // will reference the mainScreen
}
然后 [[UIScreen mainScreen] mirroredScreen]
将始终返回nil
,因为主屏幕不会自行镜像。
答案 1 :(得分:3)
Apple建议如何检测屏幕是否已镜像:http://developer.apple.com/library/ios/#qa/qa1738/_index.html
UIScreen *aScreen;
NSArray *screens = [UIScreen screens];
for (aScreen in screens)
{
if ([aScreen respondsToSelector:@selector(mirroredScreen)]
&& [aScreen mirroredScreen] == [UIScreen mainScreen])
{
// The main screen is being mirrored.
}
else
{
// The main screen is not being mirrored, or
// you are not running on a compatible device.
}
}