uikit

Dismiss a SwiftUI View that is contained in a UIHostingController

天大地大妈咪最大 提交于 2021-01-20 19:00:07
问题 I have rewritten my sign in view controller as a SwiftUI View . The SignInView is wrapped in a UIHostingController subclass ( final class SignInViewController: UIHostingController<SignInView> {} ), and is presented modally, full screen, when sign in is necessary. Everything is working fine, except I can't figure out how to dismiss the SignInViewController from the SignInView . I have tried adding: @Environment(\.isPresented) var isPresented in SignInView and assigning it to false when sign in

Dismiss a SwiftUI View that is contained in a UIHostingController

混江龙づ霸主 提交于 2021-01-20 18:56:20
问题 I have rewritten my sign in view controller as a SwiftUI View . The SignInView is wrapped in a UIHostingController subclass ( final class SignInViewController: UIHostingController<SignInView> {} ), and is presented modally, full screen, when sign in is necessary. Everything is working fine, except I can't figure out how to dismiss the SignInViewController from the SignInView . I have tried adding: @Environment(\.isPresented) var isPresented in SignInView and assigning it to false when sign in

关于SwiftUI的常见问题

僤鯓⒐⒋嵵緔 提交于 2021-01-13 07:32:28
译自: https://www.hackingwithswift.com/quick-start/swiftui/frequently-asked-questions-about-swiftui 很多人已经在问我关于SwiftUI的问题,我已经尽力请其他认识更多的人来尝试找到合适的答案。 所以,这里... 学习哪个:SwiftUI或UIKit? 这个问题被问了很多遍了,我在本书中添加了专门的章节,因此我可以更详细地讲:回答一个大问题:您应该学习SwiftUI,UIKit还是同时学习两者? SwiftUI可以在哪里使用? SwiftUI在iOS 13,macOS 10.15,tvOS 13和watchOS 6或这些平台的任何更高版本上运行。这意味着,如果您使用的应用程序必须支持iOS N-1甚至N-2(即当前版本和该版本之前的一个或两个),那么您甚至可能需要一两年的时间才能考虑迁移到SwiftUI 。 但是,重要的是不要将SwiftUI视为类似于Java的Swing或React Native的多平台框架。官方说法似乎是,SwiftUI不是一个多平台框架,而是一个用于在多个平台上创建应用程序的框架。 听起来可能是一样的,但是有一个重要的区别:Apple并不是说您可以在每个平台上使用相同的SwiftUI代码,因为有些事情是不可能的–无法在Mac上使用Apple Watch的数字王冠例如

UICollectionViewCompositionalLayout - center items in sections or groups

戏子无情 提交于 2021-01-07 02:46:41
问题 I set up a collection view and its layout with the new compositional stuff and it has been pretty cool, it seems to be very expandable but I can't find a way to make items centered in the collection, which is IMO a basic feature that one would imagine being supported.. What I have is: Accomplished with this code: UICollectionViewCompositionalLayout { section, env in let tagDefaultSize = CGSize(width: 100, height: 40) let item = NSCollectionLayoutItem( layoutSize: NSCollectionLayoutSize

UIDatePicker with .compact style doesn't respect content hugging priority

懵懂的女人 提交于 2021-01-06 03:28:50
问题 I think that the new UIDatePicker (iOS 14+) with the .compact style doesn't work correctly with AutoLayout. Making a simple layout with a UILabel and UIDatePicker where the UIDatePicker has higher content-hugging priority should result in a layout where the UILabel is being stretched if there is too much space available but that's not what happens. That's the result that I get: Here is sample code: class ViewController: UIViewController, UIGestureRecognizerDelegate { private let label:

UIDatePicker with .compact style doesn't respect content hugging priority

流过昼夜 提交于 2021-01-06 03:26:34
问题 I think that the new UIDatePicker (iOS 14+) with the .compact style doesn't work correctly with AutoLayout. Making a simple layout with a UILabel and UIDatePicker where the UIDatePicker has higher content-hugging priority should result in a layout where the UILabel is being stretched if there is too much space available but that's not what happens. That's the result that I get: Here is sample code: class ViewController: UIViewController, UIGestureRecognizerDelegate { private let label:

How to reconstruct grayscale image from intensity values?

空扰寡人 提交于 2021-01-04 12:37:12
问题 It is commonly required to get the pixel data from an image or reconstruct that image from pixel data. How can I take an image, convert it to an array of pixel values and then reconstruct it using the pixel array in Swift using CoreGraphics ? The quality of the answers to this question have been all over the place so I'd like a canonical answer. 回答1: Get pixel values as an array This function can easily be extended to a color image. For simplicity I'm using grayscale, but I have commented the

UITextField backgroundColor set in Interface Builder is nil at runtime in iOS 14

為{幸葍}努か 提交于 2020-12-30 06:15:02
问题 I have an app that works properly on iOS 11-13, but when I run it in iOS 14 several text fields within it are rendered with a nil, and so transparent, background color even though the background color is set to White explicitly in the Interface Builder. I can't see anywhere in the code that uses those text fields that might mess up the background color, and these same UITextFields running under the same scenarios appear with White background on iOS 13 and below. If I set the color explicitly

UITextField backgroundColor set in Interface Builder is nil at runtime in iOS 14

大憨熊 提交于 2020-12-30 06:13:43
问题 I have an app that works properly on iOS 11-13, but when I run it in iOS 14 several text fields within it are rendered with a nil, and so transparent, background color even though the background color is set to White explicitly in the Interface Builder. I can't see anywhere in the code that uses those text fields that might mess up the background color, and these same UITextFields running under the same scenarios appear with White background on iOS 13 and below. If I set the color explicitly

UITextField backgroundColor set in Interface Builder is nil at runtime in iOS 14

依然范特西╮ 提交于 2020-12-30 06:12:43
问题 I have an app that works properly on iOS 11-13, but when I run it in iOS 14 several text fields within it are rendered with a nil, and so transparent, background color even though the background color is set to White explicitly in the Interface Builder. I can't see anywhere in the code that uses those text fields that might mess up the background color, and these same UITextFields running under the same scenarios appear with White background on iOS 13 and below. If I set the color explicitly