Post

Replies

Boosts

Views

Activity

Sizing SpriteView inside a List
I am trying to display a SKScene inside a SwiftUI list but I'm having problems getting it to size properly. Here is the code I'm using: struct MyView: View { var scene: SKScene // this is a SKScene with .aspectFit scaling mode var body: some View { List { Section { GeometryReader { geo in SpriteView(scene: scene, options: [.allowTransparency]) .frame(height: geo.size.width / scene.size.width * scene.size.height) } } Section { Text("SomeOtherStuff") } } } } Doing this scales the actual SKScene properly but the list 'cell' doesn't stretch to fit the scene it contains, therefore clipping chunks of said scene. If I drop the GeometryReader and hard code the height, the cell resizes. My guess is that the SKScene dimensions are not yet available to SwiftUI when the GeometryReader is evaluated. Any suggestions?
2
0
583
Jan ’24
Launching iOS app from iCloud Drive
My iOS app supports a document type and includes the appropriate UTI data. It can therefore open documents of a specific type from mail attachments, for instance. It works well.I am currently stumped, however: when I open a document from the iCloud Drive app (tap document, share button, "Copy to <app>") my application gets launched but any attempts to copy the item from the provided URL fails with NSCocoaErrorDomain, error 257 (basically telling me I don't have the permissions to read the file). This issue is not present when my app is running in the background, however, and does not seem to occur when the app gets launched from a mail attachment (whether it's running ot not).I compared the URLs handed to my app and they are identical, whether the app was running or not.Here's the URL my app is handed: "file:///private/var/mobile/Library/Mobile%20Documents/com~apple~CloudDocs/filename.ext"The code I'm using is the following:// uniqueURL is a destination URL in my app's sandbox: // file:///var/mobile/Containers/Data/Application/12AB2BA0-EA63-4FAC-A7D8-779964868B06/Documents/filename.ext dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { let fileCoordinator = NSFileCoordinator(filePresenter: nil) fileCoordinator.coordinateReadingItemAtURL(url, options: .WithoutChanges, error: nil) { newURL in do { try NSFileManager.defaultManager().copyItemAtURL(newURL, toURL: uniqueURL) } catch { print("Error!") // this is where I'm getting NSCocoaErrorDomain:257 } }This issue seems to be identical to that other thread:https://forums.developer.apple.com/message/29985#29985However, I'm not running on a beta OS. My device is an iPhone 6s running iOS 9.3.2 (13F69).
Topic: UI Frameworks SubTopic: UIKit Tags:
11
3
98k
Aug ’23
SwiftUI modal: detect if full screen or stacked
I have a View that consists of a NavigationView. I set its style to .stack using .navigationViewStyle to force the 'stacked' modal look when appropriate (I am displaying it modally from UIKit using a UIHostingController). This works fine but I need the view to detect if it's actually shown using the stacked look or not at runtime (on an iPhone in landscape mode, it will be displayed as full screen and I need to add a Close/Dismiss button in that specific case). Suggestions?
0
0
1.1k
Jul ’22
UILongPressGestureRecognizer eating presented UIAlertController touches?
I have a UICollectionViewController in shared iOS/tvOS code. On iOS I use context menus while I fallback to UIAlertController (alert sheet) triggered by a long press on tvOS. viewDidLoad: override func viewDidLoad() {     super.viewDidLoad() // ...     #if os(tvOS)     let longPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(longPressAction(_:))) collectionView.addGestureRecognizer(longPressGestureRecognizer)     #endif } Selector: #if os(tvOS) @objc func longPressAction(_ sender: UIGestureRecognizer) {     guard sender.state == .began else {         return     }     if let indexPath = collectionView.indexPathForItem(at: sender.location(in: collectionView)) {         let ac = UIAlertController(/* ... */) // alert sheet         present(ac, animated: true, completion: nil)     } } #endif Upon long pressing, the alert sheet gets displayed properly on tvOS but the first tap on one of the sheet actions is ignored (this calls longPressAction again with a .cancel state). I tried inserting a sender.isEnabled = false after the guard but it simply caused the .cancel state to come in faster while still eating the first tap. Suggestions?
1
0
1k
Mar ’22
UITableView reloadRows resets focus
I have a UITableViewController shared between my iOS and tvOS apps. In order to refresh some of the cells, I call reloadRows. It works fine as far as updating the cell's data but, on tvOS, it moves the focus back to the top of the table. I've noticed that preferredFocusEnvironments does not get called (unlike what happens when I do reloadData). This is pretty much the same issue mentioned in the following post (years ago): https://developer.apple.com/forums/thread/67219 Any suggestions?
2
1
1.9k
Mar ’22
Picking .bin files with UIDocumentPickerViewController
My iOS app needs to open data files from iCloud drive to flash some of our devices. We use .hex and .bin file extensions. I'm supplying the appropriate document types to UIDocumentPickerViewController (I have also defined them in my Info.plist's Imported UTIs section). UIDocumentPickerViewController keeps the .bin files grayed out, however. I understand that these fall under the system defined "com.apple.macbinary-archive" type. Is there any way to let the document picker mark those as available or should I just rely on renaming the file?
Topic: UI Frameworks SubTopic: UIKit Tags:
1
0
1.6k
Mar ’22
UIToolbar in SwiftUI?
I've been experimenting with SwiftUI and couldn't figure out how to get a simple UIToolbar to appear at the bottom of the screen.Basic view:struct MyView : View { var body: some View { NavigationView { List { NavigationButton(destination: Text("1")) { Text("Element 1") } // ... }.navigationBarTitle(Text("Elements")) } } }
4
0
8.5k
Jun ’21
Sizing SpriteView inside a List
I am trying to display a SKScene inside a SwiftUI list but I'm having problems getting it to size properly. Here is the code I'm using: struct MyView: View { var scene: SKScene // this is a SKScene with .aspectFit scaling mode var body: some View { List { Section { GeometryReader { geo in SpriteView(scene: scene, options: [.allowTransparency]) .frame(height: geo.size.width / scene.size.width * scene.size.height) } } Section { Text("SomeOtherStuff") } } } } Doing this scales the actual SKScene properly but the list 'cell' doesn't stretch to fit the scene it contains, therefore clipping chunks of said scene. If I drop the GeometryReader and hard code the height, the cell resizes. My guess is that the SKScene dimensions are not yet available to SwiftUI when the GeometryReader is evaluated. Any suggestions?
Replies
2
Boosts
0
Views
583
Activity
Jan ’24
Launching iOS app from iCloud Drive
My iOS app supports a document type and includes the appropriate UTI data. It can therefore open documents of a specific type from mail attachments, for instance. It works well.I am currently stumped, however: when I open a document from the iCloud Drive app (tap document, share button, "Copy to <app>") my application gets launched but any attempts to copy the item from the provided URL fails with NSCocoaErrorDomain, error 257 (basically telling me I don't have the permissions to read the file). This issue is not present when my app is running in the background, however, and does not seem to occur when the app gets launched from a mail attachment (whether it's running ot not).I compared the URLs handed to my app and they are identical, whether the app was running or not.Here's the URL my app is handed: "file:///private/var/mobile/Library/Mobile%20Documents/com~apple~CloudDocs/filename.ext"The code I'm using is the following:// uniqueURL is a destination URL in my app's sandbox: // file:///var/mobile/Containers/Data/Application/12AB2BA0-EA63-4FAC-A7D8-779964868B06/Documents/filename.ext dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { let fileCoordinator = NSFileCoordinator(filePresenter: nil) fileCoordinator.coordinateReadingItemAtURL(url, options: .WithoutChanges, error: nil) { newURL in do { try NSFileManager.defaultManager().copyItemAtURL(newURL, toURL: uniqueURL) } catch { print("Error!") // this is where I'm getting NSCocoaErrorDomain:257 } }This issue seems to be identical to that other thread:https://forums.developer.apple.com/message/29985#29985However, I'm not running on a beta OS. My device is an iPhone 6s running iOS 9.3.2 (13F69).
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
11
Boosts
3
Views
98k
Activity
Aug ’23
Using SF Symbols on iOS 13 and falling back to assets on iOS 12
Is this something that's possible (I'm using storyboards)? I'd like to update my bar button items to SF Symbols (for consistency, since I have some iOS 13 context menus using SF Symbols).
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
9
Boosts
0
Views
9.6k
Activity
Jun ’23
SwiftUI modal: detect if full screen or stacked
I have a View that consists of a NavigationView. I set its style to .stack using .navigationViewStyle to force the 'stacked' modal look when appropriate (I am displaying it modally from UIKit using a UIHostingController). This works fine but I need the view to detect if it's actually shown using the stacked look or not at runtime (on an iPhone in landscape mode, it will be displayed as full screen and I need to add a Close/Dismiss button in that specific case). Suggestions?
Replies
0
Boosts
0
Views
1.1k
Activity
Jul ’22
UILongPressGestureRecognizer eating presented UIAlertController touches?
I have a UICollectionViewController in shared iOS/tvOS code. On iOS I use context menus while I fallback to UIAlertController (alert sheet) triggered by a long press on tvOS. viewDidLoad: override func viewDidLoad() {     super.viewDidLoad() // ...     #if os(tvOS)     let longPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(longPressAction(_:))) collectionView.addGestureRecognizer(longPressGestureRecognizer)     #endif } Selector: #if os(tvOS) @objc func longPressAction(_ sender: UIGestureRecognizer) {     guard sender.state == .began else {         return     }     if let indexPath = collectionView.indexPathForItem(at: sender.location(in: collectionView)) {         let ac = UIAlertController(/* ... */) // alert sheet         present(ac, animated: true, completion: nil)     } } #endif Upon long pressing, the alert sheet gets displayed properly on tvOS but the first tap on one of the sheet actions is ignored (this calls longPressAction again with a .cancel state). I tried inserting a sender.isEnabled = false after the guard but it simply caused the .cancel state to come in faster while still eating the first tap. Suggestions?
Replies
1
Boosts
0
Views
1k
Activity
Mar ’22
UITableView reloadRows resets focus
I have a UITableViewController shared between my iOS and tvOS apps. In order to refresh some of the cells, I call reloadRows. It works fine as far as updating the cell's data but, on tvOS, it moves the focus back to the top of the table. I've noticed that preferredFocusEnvironments does not get called (unlike what happens when I do reloadData). This is pretty much the same issue mentioned in the following post (years ago): https://developer.apple.com/forums/thread/67219 Any suggestions?
Replies
2
Boosts
1
Views
1.9k
Activity
Mar ’22
Picking .bin files with UIDocumentPickerViewController
My iOS app needs to open data files from iCloud drive to flash some of our devices. We use .hex and .bin file extensions. I'm supplying the appropriate document types to UIDocumentPickerViewController (I have also defined them in my Info.plist's Imported UTIs section). UIDocumentPickerViewController keeps the .bin files grayed out, however. I understand that these fall under the system defined "com.apple.macbinary-archive" type. Is there any way to let the document picker mark those as available or should I just rely on renaming the file?
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
1
Boosts
0
Views
1.6k
Activity
Mar ’22
UIToolbar in SwiftUI?
I've been experimenting with SwiftUI and couldn't figure out how to get a simple UIToolbar to appear at the bottom of the screen.Basic view:struct MyView : View { var body: some View { NavigationView { List { NavigationButton(destination: Text("1")) { Text("Element 1") } // ... }.navigationBarTitle(Text("Elements")) } } }
Replies
4
Boosts
0
Views
8.5k
Activity
Jun ’21