uiscreen

Does iOS send notifications when the system changes the screen brightness?

老子叫甜甜 提交于 2019-12-01 03:52:54
问题 Problem is, my reading app has a button that puts it into dark theme mode. The brightness gets reduced by 10%. When the user returns to the normal mode, it is set back to the remembered brightness. But in the meantime the actual system brightness could have changed due to auto-brightness adjustment or even the user going to Settings and changing it there. The problem with the brightness property is that you only query actual screen brightness and whatever you set is only temporarily until the

UIScreen bounds versus applicationFrame

本小妞迷上赌 提交于 2019-11-30 03:52:41
Why do I see in some sample code from Apple (such as PhotoScroller) that I should do the following in loadView : CGRect frame = [[UIScreen mainScreen] bounds]; instead of CGRect frame = [[UIScreen mainScreen] applicationFrame]; Does it make a difference to get the main screen's frame? ApplicationFrame is the screen size minus the size of the status bar (if visible), bounds is the screen size regardless of status bar. So applicationFrame would return CGRectMake(0,0,320,460) assuming your app has the status bar set to be visible, while bounds would return CGRectMake(0,0,320,480) under the same

Adjust the main screen brightness using Swift

不羁的心 提交于 2019-11-30 03:20:36
问题 I would like to adjust the iPhone's main screen brightness in code using Swift. I know in Objective-C it can be done by: [[UIScreen mainScreen] setBrightness:0.5]; How do I do this in Swift? 回答1: https://developer.apple.com/documentation/uikit/uiscreen/1617830-brightness From the docs the proper answer for Swift 3+ is: UIScreen.main.brightness = CGFloat(0.5) 回答2: Actually in Swift 3 mainScreen was replaced with main , so proper code is: UIScreen.main.brightness = CGFloat(0.5) 来源: https:/

How to get device width and height?

断了今生、忘了曾经 提交于 2019-11-29 20:50:17
In Objective-C we can get device width and height by using following code : CGRect sizeRect = [UIScreen mainScreen].applicationFrame float width = sizeRect.size.width float height = sizeRect.size.height How can do this in with Swift ? iPatel I haven't tried but it should be.. var bounds = UIScreen.main.bounds var width = bounds.size.width var height = bounds.size.height @Houssni 's answer is correct, but since we're talking Swift and this use case will come up often, one could consider extending CGRect similar to this: extension CGRect { var wh: (w: CGFloat, h: CGFloat) { return (size.width,

UIScreen bounds versus applicationFrame

可紊 提交于 2019-11-29 01:24:21
问题 Why do I see in some sample code from Apple (such as PhotoScroller) that I should do the following in loadView : CGRect frame = [[UIScreen mainScreen] bounds]; instead of CGRect frame = [[UIScreen mainScreen] applicationFrame]; Does it make a difference to get the main screen's frame? 回答1: ApplicationFrame is the screen size minus the size of the status bar (if visible), bounds is the screen size regardless of status bar. So applicationFrame would return CGRectMake(0,0,320,460) assuming your

How to change brightness in iOS 5 app?

独自空忆成欢 提交于 2019-11-28 21:19:16
How would I program the ability to change brightness in-app? I know that its possible as I have seen at least three apps that can do it. This would be very useful for my app. I know that it's only possible in iOS 5 with the UIScreen Class, but I have no idea how to program it. Please help me! The UIScreen class has a new property called brightness . In addition, there's another property called wantsSoftwareDimming that (when set to YES ) allows you to go below the lowest brightness supported by the hardware, because a special "dimming view" is overlaid over the screen to darken things even

Capturing full screenshot with status bar in iOS programmatically

…衆ロ難τιáo~ 提交于 2019-11-28 19:39:39
I am using this code to capture a screenshot and to save it to the photo album. -(void)TakeScreenshotAndSaveToPhotoAlbum { UIWindow *window = [UIApplication sharedApplication].keyWindow; if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) UIGraphicsBeginImageContextWithOptions(window.bounds.size, NO, [UIScreen mainScreen].scale); else UIGraphicsBeginImageContext(window.bounds.size); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); UIImageWriteToSavedPhotosAlbum(image, nil,

What is the difference between -nativeScale and -scale on UIScreen in iOS8+?

▼魔方 西西 提交于 2019-11-28 18:13:59
In sample logs posted in this question , the results are identical. Does anyone know if there is meant to be a logical difference between the two? Even Apple's description is confusing. Here is the description of scale : The natural scale factor associated with the screen ... This value reflects the scale factor needed to convert from the default logical coordinate space into the device coordinate space of this screen... Here is their description of nativeScale : The native scale factor for the physical screen What is the difference between natural and native ? The nativeBounds and nativeScale

How to get device width and height?

北战南征 提交于 2019-11-28 16:57:03
问题 In Objective-C we can get device width and height by using following code : CGRect sizeRect = [UIScreen mainScreen].applicationFrame float width = sizeRect.size.width float height = sizeRect.size.height How can do this in with Swift ? 回答1: I haven't tried but it should be.. var bounds = UIScreen.main.bounds var width = bounds.size.width var height = bounds.size.height 回答2: @Houssni 's answer is correct, but since we're talking Swift and this use case will come up often, one could consider

UIScreen Brightness Property

自古美人都是妖i 提交于 2019-11-28 07:44:05
问题 At the moment I'm trying to create an application to adjust the device's brightness. In iOS5, there is the new brightness property for mainScreen that allows you to set the screen brightness. I'm using the following code: [[UIScreen mainScreen] setBrightness:1.0]; However this seems to only work until the device is locked, and doesn't get saved in settings. Is there something I'm doing wrong? 回答1: You will need to save the value you want to set yourself in your NSUserDefaults and call