为什么我在Apple的一些示例代码(例如PhotoScroller)中看到我应该执行以下操作loadView:
CGRect frame = [[UIScreen mainScreen] bounds];
Run Code Online (Sandbox Code Playgroud)
代替
CGRect frame = [[UIScreen mainScreen] applicationFrame];
Run Code Online (Sandbox Code Playgroud)
获得主屏幕的框架是否有所不同?
我的应用程序(音乐家的节拍器应用程序)中有一项功能可以调暗屏幕以节省电池寿命.要设置亮度,我正在使用:
[UIScreen mainScreen].brightness = 0.1;
Run Code Online (Sandbox Code Playgroud)
我在viewDidLoad(...)中启动app保存原始亮度并将其保存到我的用户默认值.
在应用程序中更改视图时,我从用户默认值中检索原始亮度并通过调用恢复:
[UIScreen mainScreen].brightness = originalBrightness;
Run Code Online (Sandbox Code Playgroud)
这很好用.我有NSLog(...)消息显示原始值等...所以机制工作.
我遇到的问题是如何在按下主页按钮时恢复应用程序退出时的原始亮度.
我已经为我的应用程序委托方法添加了类似的代码:
applicationWillResignActive(...)
applicationDidEnterBackground(...)
applicationWillTerminate(...)
Run Code Online (Sandbox Code Playgroud)
它们每个都有一个方法调用,用于在视图中设置屏幕亮度,类似的NSLog(...)显示检索到的原始亮度...并且它都是正确的.我也已调试并且正在调用设置亮度...但是应用程序退出,设备屏幕仍处于较低的调暗级别.
最后,如果单击顶部的"锁定"按钮,然后按"主页"按钮将其唤醒...亮度正确.
我的怀疑是,当应用程序退出时我设置亮度的调用触发的任何操作或事件都没有通过,可能是由于状态无效或类似.
此外,我的应用程序设置为不在后台运行,在info.plist中设置为:
Application does not run in background YES
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.
谢谢!
可能重复:
如何使用代码获取屏幕大小?
NSLog(@"Top Left View : Width %f height%f",self.topLeftView.frame.size.width,self.topLeftView.frame.size.height);
Run Code Online (Sandbox Code Playgroud)
我从对象库中拖出了"View"并将其放在xib文件中.
但是,如果我想获得屏幕尺寸来检查它的iphone 4,iPhone 3或iphone 5或任何iOS设备.
这样我就可以相应地安排其他观点.
我试图找出iOS中的PPI(Pixils Per Inch).
我找不到任何直接的方法来查询这个,就像我们对显示大小一样
UIScreen.mainScreen().bounds
Run Code Online (Sandbox Code Playgroud)
有一种方法可以通过将尺度与iPhone(163)或iPad(132)的标准通用PPI相乘来实现,但这并不准确.
如果公式是正确的那么PPI的iPhone 6 plus是489,但在现实的PPI为401这里是参考
现在似乎硬编码是要走的路.
但我想使用公式以编程方式进行.
我想用Swift在代码中调整iPhone的主屏亮度.
我在Objective-C中知道它可以通过以下方式完成:
[[UIScreen mainScreen] setBrightness:0.5];
Run Code Online (Sandbox Code Playgroud)
我如何在Swift中执行此操作?
我正在使用HDMI线将iPad屏幕输出到电视上.如果我将iPad保持在横向模式,电视节目的输出将以横向模式显示.如果我将它旋转到电视上的肖像输出也改为纵向模式.
有没有办法限制这一点,即使我将iPad旋转到纵向,电视上的输出应保持在横向
这里有一些图片可以说明我的问题
这是我的iPad的定位......

这就是我得到的.........

这就是我要的......
要么 
从乱搞编程我到目前为止..
我在UIImageView上创建了一个带有一些图像的按钮,在Xcode的单个视图应用程序模板中使用IBaction方法,此方法具有以下代码
- (IBAction)screenButton:(id)sender {
NSLog(@"Screen Count %d",[[UIScreen screens]count]);
if([[UIScreen screens]count] > 1) {
CGSize max;
UIScreenMode *maxScreenMode;
for(int i = 0; i < [[[[UIScreen screens] objectAtIndex:1] availableModes]count]; i++)
{
UIScreenMode *current = [[[[UIScreen screens]objectAtIndex:1]availableModes]objectAtIndex:i];
if(current.size.width > max.width)
{
max = current.size;
maxScreenMode = current;
}
}
//UIScreen *external = [[UIScreen screens] objectAtIndex:0];
UIScreen *external = [[UIScreen screens] objectAtIndex:1];
external.currentMode = maxScreenMode;
//external_disp = [externalDisplay alloc];
//external_disp.drawImage = drawViewController.drawImage;
// ExternalDisplayOn = TRUE; …Run Code Online (Sandbox Code Playgroud) 我正在学习如何在没有Interface Builder(即故事板,xib等)的情况下创建iOS应用程序.下面是我正在使用的基本应用程序委托类.问题是,显示时UIWindow不会耗尽设备的全屏(参见附件截图).这发生在我测试的所有设备和模拟器上.为什么不使用全屏?
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
lazy var window: UIWindow? = {
debugPrint("AppDelegate: Creating Window")
let screen: UIScreen = UIScreen.mainScreen()
let window: UIWindow = UIWindow.init(frame: screen.bounds)
window.backgroundColor = UIColor.whiteColor()
return window
}()
lazy var rootViewController: ShapesViewController = {
debugPrint("AppDelegate: Creating Root View Controller")
let rootViewController = ShapesViewController.init(nibName: nil, bundle: nil)
return rootViewController
}()
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
debugPrint("AppDelegate: applicationWillEnterForeground")
window?.rootViewController = rootViewController
window?.makeKeyAndVisible()
return true
}
}
Run Code Online (Sandbox Code Playgroud)
我试图在用户看到它时获得整个屏幕的图像.以下代码应该可以工作,但它只能在模拟器中工作.我该怎么做才能让这个在运行iOS 8.1的设备上运行?
UIView *snapshot = [[UIScreen mainScreen] snapshotViewAfterScreenUpdates:YES];
CGSize outputSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
UIGraphicsBeginImageContextWithOptions(outputSize, NO, 0);
[snapshot drawViewHierarchyInRect:CGRectMake(0.0, 0.0, outputSize.width, outputSize.height) afterScreenUpdates:YES];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Run Code Online (Sandbox Code Playgroud)
很高兴尝试其他策略,但关键是我想要它,因为用户看到它 - 键盘和所有.
干杯
我试图用我自己的视图覆盖状态栏并且这样做我通过做类似的事情(也在旋转之后)为我的视图计算框架:
UIScreen *screen = [UIScreen mainScreen];
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
Run Code Online (Sandbox Code Playgroud)
对于iOS8 +(因为UIScreenios8依赖于取向):
CGRect frame = [screen.coordinateSpace convertRect:statusBarFrame toCoordinateSpace:screen.fixedCoordinateSpace];
[self setFrame:frame];
Run Code Online (Sandbox Code Playgroud)
对于iOS7:
[self setFrame:statusBarFrame];
Run Code Online (Sandbox Code Playgroud)
它适用于iOS8及以下版本,但在使用Xcode 7 beta 4和iOS 9 SDK构建我的应用程序时,在横向或颠倒启动应用程序时出现问题(如果应用程序以纵向方式启动,则工作正常)...
即.当我在颠倒时启动应用程序时,应该覆盖状态栏的自定义uiwindow将始终位于屏幕的底部,任何想法可能出错?
目前我正在尝试创建一个应用程序来调整设备的亮度.在iOS5中,mainScreen有一个新的亮度属性,允许您设置屏幕亮度.我正在使用以下代码:
[[UIScreen mainScreen] setBrightness:1.0];
Run Code Online (Sandbox Code Playgroud)
但是,这似乎只有在设备被锁定后才能工作,并且不会保存在设置中.有什么我做错了吗?
uiscreen ×10
ios ×8
objective-c ×3
swift ×3
iphone ×2
uiwindow ×2
brightness ×1
cocoa-touch ×1
ios5 ×1
ios8 ×1
ios9 ×1
ipad ×1
mainwindow ×1
mobile ×1
ppi ×1
statusbar ×1
uialertview ×1
uikit ×1