As can be seen in the screenshot attached, I can not see the options in this window. A prompt window before this also did not show any buttons in the visible space. However, I made a guess and could get to this window by clicking on what I think was "Ok" or something similar.
But on this I could not do any action and had to force quit the app.
Explore the various UI frameworks available for building app interfaces. Discuss the use cases for different frameworks, share best practices, and get help with specific framework-related questions.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hi all,
I am developing an app that scans barcodes using VisionKit, but I am facing some difficulties.
The accuracy level is not at where I hope it to be at. Changing the “qualityLevel” parameter from balanced to accurate made the barcode reading slightly better, but it is still misreading some cases. I previously implemented the same barcode scanning app with AVFoundation, and that had much better accuracy. I tested it out, and barcodes that were read correctly with AVFoundation were read incorrectly with VisionKit . Is there anyway to improve the accuracy of the barcode reading in VisionKit? Or is this something that is built in and the developer cannot change? Either way, any ideas on how to improve reading accuracy would help.
Thanks in advance!
I have a UIKit application and it contains multiple UI components like UIWindow, UIView, UIButton, etc. I wanted to perform error handling for different OS calls in my application.
For example, when creating a UIImage using init(named:) initialiser, the documentation clearly states that if the UIImage object cannot be created then the initialiser returns nil value.
However, there are other UI components like UIButton (or like UIView), which when created using init(frame:)
initialiser, the documentation does not mention for any return value.
I wanted to know how to identify If the UIButton initialisation has failed?
How is it that apple recommends should we handle these api's, If they fail to create a button. suppose If there is a case where it fails due to insufficient memory.
Or is it that apple guarantees the Api's never fail?Is there some exception that is throw? I wanted somewhat detailed answer to these questions.
I've encountered what appears to be a bug with widget background image tinting in SwiftUI. When using an image in containerBackground(for: .widget) to fill the entire widget, adding the .containerBackgroundRemovable(false) modifier breaks the widget's tinting behavior:
The background image becomes permanently tinted, ignoring any widgetAccentedRenderingMode(_ renderingMode: WidgetAccentedRenderingMode?) settings
Text elements become tinted even with .widgetAccentable(false) applied
Sample code:
struct MyWidget: Widget {
var body: some WidgetConfiguration {
AppIntentConfiguration(kind: "MyWidget", intent: MyWidgetIntent.self, provider: Provider()) { entry in
MyWidgetView(entry: entry)
.containerBackground(for: .widget) {
Image("background")
.resizable()
.widgetAccentedRenderingMode(.fullColor)
.scaledToFill()
}
}
.containerBackgroundRemovable(false) // This causes the issue
}
}
Workaround: I've managed to resolve this by using a ZStack with disabled content margins and passing the widget size through the entry. However, this seems like unintended behavior with the .containerBackgroundRemovable(false) modifier.
Has anyone else encountered this issue or found a better solution?
Device: iPhone 15 Pro
iOS Version: 18.1
Xcode Version: 16.1
Hello,
I am experiencing a performance regression in my application when rendering volumes on iPhone. Specifically, I have noticed that iOS version 18.2 takes significantly more time for each render cycle as compared to iOS 18.1.
Details:
Affected Versions:
iOS version 18.2
iOS version 18.1 (baseline for comparison)
Issue Description:
In iOS version 18.2, the time taken to render volumes has increased compared to iOS version 18.1. This performance regression is affecting the user experience in my application.
Test Example:
https://www.cornerstonejs.org/live-examples/volumeviewport3d
Steps to Reproduce:
Load the above test example on an iPhone running version 18.2 using safari.
Perform volume rendering using the provided dataset.
Measure the time taken by volume for each rotate or drag action.
Repeat the same steps on an iPhone running version 18.1 for comparison.
Additional Information:
Device Model Tested:
iPhone12, iPhone13, iPhone14
iOS Version With Issue:
18.2
18.3(Beta)
I would appreciate any insights or suggestions on how to address this performance regression. If additional information is needed, please let me know.
Thank you.
Hi,
I would like to create an app that has a volumetric window in the middle and two 2D windows on the sides. When I tried that, the 2D windows are positioned slightly below the volumetric window for some reason (image1).
Looks like the base (hadle, close button, etc.) of the volumetric window is aligned with the center of the whole 2D window. I would like all the window bases to be aligned (image2). (I can of course do this manually by dragging the window down a bit with my hand, but that’s an inconvenience for my usecase.)
I tried making the whole volumetric window content higher, but that did not help and the content actually went far above the 2D windows (image3).
I suppose this was some design choice when creating the whole window positioning behavior on VisionOS.
Am I doing something wrong? Is there a way to achieve what I want or a better way to customize the position of windows, not just 5 predefined positions in defaultWindowPlacement?
Image1 - current:
Image2 - what I want:
Image3 - current, larger content:
Code:
import SwiftUI
@main
struct placementTestApp: App {
@Environment(\.openWindow) var openWindowAction
var body: some Scene {
WindowGroup(id: "volume") {
VolumetricWindowView()
.onAppear {
openWindowAction(id: "first")
openWindowAction(id: "second")
}
}
.windowStyle(.volumetric)
.volumeWorldAlignment(.gravityAligned)
WindowGroup(id: "first") {
NormalWindowView()
}
.defaultWindowPlacement { _, context in
if let mainWindow = context.windows.first(where: { $0.id == "volume" }) {
WindowPlacement(.leading(mainWindow))
} else {
WindowPlacement()
}
}
WindowGroup(id: "second") {
NormalWindowView()
}
.defaultWindowPlacement { _, context in
if let mainWindow = context.windows.first(where: { $0.id == "volume" }) {
WindowPlacement(.trailing(mainWindow))
} else {
WindowPlacement()
}
}
}
}
我最近在18.0,18.1,18.1.1上监测到一个特殊的崩溃,无法复现,且页面日志都跟键盘有关,有没有什么思路能够处理这个问题。
0 CoreFoundation 0x00000001a224d08c __exceptionPreprocess + [ : 164] 1 libobjc.A.dylib 0x000000019f54f2e4 objc_exception_throw + [ : 88] 2 Foundation 0x00000001a161e15c _userInfoForFileAndLine 3 UIKitCore 0x00000001a56c6b2c -[UIView _multiLayerDelegatesTableCreateIfNecessary:] + [ : 208] 4 UIKitCore 0x00000001a56c6b7c -[UIView _registerMultiLayerDelegate:] + [ : 36] 5 UIKitCore 0x00000001a4ceadb8 -[_UIPortalView setSourceView:] + [ : 132] 6 UIKitCore 0x00000001a5a35888 -[_UIPortalView initWithSourceView:] + [ : 68] 7 UIKitCore 0x00000001a5a5e038 -[_UITextMagnifiedLoupeView initWithSourceView:] + [ : 444] 8 UIKitCore 0x00000001a5f0f894 +[UITextLoupeSession _makeLoupeViewForSourceView:selectionWidget:orientation:] + [ : 84] 9 UIKitCore 0x00000001a5f0fa34 +[UITextLoupeSession _beginLoupeSessionAtPoint:fromSelectionWidgetView:inView:orientation:] + [ : 304] 10 UIKitCore 0x00000001a55a0b9c -[UITextRefinementTouchBehavior textLoupeInteraction:gestureChangedWithState:location:translation:velocity:modifierFlags:shouldCancel:] + [ : 1756] 11 UIKit 0x000000025aff6310 -[UITextRefinementTouchBehaviorAccessibility textLoupeInteraction:gestureChangedWithState:location:translation:velocity:modifierFlags:shouldCancel:] + [ : 216]
Topic:
UI Frameworks
SubTopic:
UIKit
I have a very annoying problem editing a property of one of my model structs: the binding var (subject) property (gender) is updated only once by a selection list.
The first time I use my control, all works correctly; from the second time on, nothing happens (not even an .onChange() placed for debug... it simply doesn't fire up).
EVEN MORE STRANGE BEHAVIOR:
The SAME control, copied inside an Apple sample projects works perfectly (Recipies Sample, downloaded from Apple Developer site). This sample project is, I guess, at least two years old, still with @ObservableObject, @Publish, ...and so on, that I converted to @Observable protocol.
FINAL CHERRY ON THE CAKE: THE SAME sample Project, copied ASIS into a new Xcode projects, doesn't work anymore!
It seems an error buried deep inside Xcode compiler optimizations (maybe to avoid unnecessary views redraw carried too far...).
Anyway: I'm asking for help, because I'm not able to see any reason for this behavior and - just to add a bit of frustration - a working project developed with Xcode 15, without any problem (Stager, available on the App Store), reopenend with Xcode 16 acquires the same odd behavior.
Any Apple developer can help?
Many thanks in advace
Simplified code follows (I made a new project just with the few things needed to show the case)
MODEL
import Foundation
import SwiftUI
enum Gender : String, Codable, CaseIterable, Equatable {
case male = "M"
case female = "F"
case nonbinary = "N"
case unknown = "U"
var description : String {
switch self {
case .male : "Male"
case .female : "Female"
case .nonbinary : "Not binary"
case .unknown : "Unknown"
}
}
var iconName : String {
"iconGender\(self.rawValue)"
}
}
struct Subject : Identifiable, Codable, Equatable, Hashable {
var id : Int
var name : String
var surname : String
var nickName : String // Identificativo alternativo all’anagrafica
var gender : Gender // Sesso del soggetto [ M | F | * ]
var imageName : String {
"foto" + self.nickName.replacingOccurrences(of: " ", with: "") + ".jpg"
}
static func == (lhs: Subject, rhs: Subject) -> Bool {
return (lhs.id, lhs.nickName, lhs.surname, lhs.name) == (rhs.id, rhs.nickName, rhs.surname, rhs.name)
}
static func emptySubject() -> Subject {
return Subject(id: -1, name: "", surname: "", nickName: "", gender: .unknown)
}
func hash(into hasher: inout Hasher) {
hasher.combine(id)
hasher.combine(nickName)
hasher.combine(surname)
hasher.combine(name)
}
}
CONTROL
import SwiftUI
struct FormPickerGender: View {
@Binding var value : Gender
let isEdit : Bool
@State var presentPicker : Bool = false
var body: some View {
HStack {
Text("Gender:").foregroundStyle(.gray).italic()
if isEdit {
Image(systemName: "text.magnifyingglass")
.foregroundStyle(.tint)
.onTapGesture {
presentPicker = true
}
}
Text("\(value.description)")
}
.sheet(isPresented: $presentPicker, content: {
PickGender(currentGender: $value)
})
}
}
struct PickGender: View {
@Environment(\.dismiss) var dismiss
@Binding var currentGender : Gender
var body: some View {
Text("Gender selection")
.font(.title2)
.foregroundStyle(.tint)
Button("Cancel") {
dismiss()
}
.buttonBorderShape(.capsule)
List {
ForEach(Gender.allCases, id: \.self) { genderCase in
HStack {
Image("\(genderCase.iconName)")
if currentGender == genderCase {
Text(genderCase.description)
.font(.title3)
.foregroundStyle(.blue)
} else {
Text(genderCase.description)
.font(.title3)
}
Spacer()
}
.onTapGesture {
currentGender = genderCase
dismiss()
}
}
.listRowInsets(EdgeInsets(top: 10, leading: 50, bottom: 10, trailing: 50))
}
}
}
struct GenderPreviewWrapper: View {
@State var subject = Subject.emptySubject()
var body: some View {
Form {
FormPickerGender(value: $subject.gender, isEdit: true)
}
}
}
#Preview {
return GenderPreviewWrapper()
}
Just for completion... If instead of $subject.gender, I use a state variable valued with gender and then $stateGender it works, but to create a specific state var for EACH property of a structure, seems to me to nullify the concept itself of struct: why bother to foreseen properties, if you can't manage them as a whole?
Probably the solution will be to create a specific CLASS object of the STRUCT object, just for edit... something like :
static func <STRUCT>.getEditObject() -> classObject
static func <CLASS>.getStructObject() -> structObject
...once again: why have structs?
Topic:
UI Frameworks
SubTopic:
SwiftUI
I want to use Objective C language to implement a button, click the button to achieve the function of Menu Bar - Full Screen Tile - Left of Screen. What should I do? I couldn't find the relevant API.
Topic:
UI Frameworks
SubTopic:
AppKit
Hi,
I'm experiencing a layout issue in SwiftUI when using TabView, NavigationStack, and a List in a specific navigation flow. Here's how to reproduce it:
Tap on Tab 3.
Tap "Tap Me to go to the subview" to navigate to the detail view.
In the detail view, tap Back to return to Tab 3.
Tap "Tap Me to go to the subview" again.
Problem: When returning to the detail view, the content (especially the List) appears incorrectly positioned within the safe area, as if it's overlapping or misaligned with the navigation bar. This happens only when navigating back and forth after dismissing a sheet presented from a different tab.
This animated gif shows the workflow to visualize the problem:
Expected Behavior: The content should consistently respect the safe area and be positioned correctly under the navigation bar.
Thanks in advance for your help!
Here is the complete code to reproduce the issue:
import SwiftUI
@Observable
class MenuSelector {
var initialIndex: Int
var customTabIndex: Int
var isCustomTabSelected: Bool = false
private var previousIndex: Int
init(customTabIndex: Int, initialIndex: Int = 0) {
self.initialIndex = initialIndex
self.customTabIndex = customTabIndex
self.itemSelected = initialIndex
self.previousIndex = initialIndex
}
var itemSelected: Int {
didSet {
if itemSelected == customTabIndex {
previousIndex = oldValue
itemSelected = oldValue
isCustomTabSelected = true
}
}
}
}
struct NavigationStackSpikeView: View {
@State private var tabSelector = MenuSelector(customTabIndex: 1)
var body: some View {
TabView(selection: $tabSelector.itemSelected) {
Text("Tab 1")
.tabItem {
Text("Tab 1")
}
.tag(0)
Text("I want to present a sheet for this tab")
.tabItem {
Text("Action")
}
.tag(1)
Tab3View()
.tabItem {
Text("Tab 3")
}
.tag(2)
}
.sheet(isPresented: $tabSelector.isCustomTabSelected) {
SheetView()
}
}
}
struct Tab3View: View {
@State private var navigationPath = NavigationPath()
var body: some View {
NavigationStack(path: $navigationPath) {
VStack {
NavigationLink(value: Destination.subview) {
Text("Tap Me to go to the subview")
}
}
.navigationDestination(for: Destination.self) { destination in
switch destination {
case .subview:
DetailView()
}
}
}
}
enum Destination: Hashable {
case subview
}
}
struct DetailView: View {
var body: some View {
VStack {
List {
Text("A detail")
}
.listStyle(.plain)
}
.navigationTitle("Details")
.navigationBarTitleDisplayMode(.inline)
}
}
struct SheetView: View {
@Environment(\.dismiss) var dismiss
var body: some View {
VStack {
Text("I'm a sheet")
Button("Dismiss") { dismiss() }
}
}
}
#Preview {
NavigationStackSpikeView()
}
import Cocoa
@available(macOS 10.13, *)
let imagePboardType = NSPasteboard.PasteboardType.fileURL
class DragSourceView: NSImageView {
weak var dragSourceDelegate: NSDraggingSource?
override func mouseDown(with event: NSEvent) {
//拖放数据定义
let pasteboardItem = NSPasteboardItem()
//设置数据的Provider
if #available(macOS 10.13, *) {
pasteboardItem.setDataProvider(self, forTypes: [NSPasteboard.PasteboardType.fileURL])
} else {
// Fallback on earlier versions
}
//拖放item
let draggingItem = NSDraggingItem(pasteboardWriter: pasteboardItem)
draggingItem.draggingFrame = NSRect(x: 100 , y: 10, width: 100, height: 100)
//拖放可视化图象设置
draggingItem.imageComponentsProvider = {
let component = NSDraggingImageComponent(key: NSDraggingItem.ImageComponentKey.icon)
component.frame = NSRect(x: 0, y: 0, width: 16, height: 16)
component.contents = NSImage(size: NSSize(width: 32,height: 32), flipped: false, drawingHandler: { [unowned self] rect in {
self.image?.draw(in: rect)
return true
}()
}
)
return [component]
}
//开始启动拖放sesson
self.beginDraggingSession(with: [draggingItem], event: event, source: self.dragSourceDelegate!)
}
}
extension DragSourceView: NSPasteboardItemDataProvider {
func pasteboard(_ pasteboard: NSPasteboard?, item: NSPasteboardItem, provideDataForType type: NSPasteboard.PasteboardType) {
// let data = self.image?.tiffRepresentation
let data = "/Users/slowdony/Desktop/640.jpeg"
let dataUrl = data.data(using: String.Encoding(rawValue: NSUTF8StringEncoding))!
item.setData(dataUrl, forType: type)
}
}
import Cocoa
class ViewController: NSViewController {
@IBOutlet weak var sourceView: DragSourceView!
override func viewDidLoad() {
super.viewDidLoad()
self.sourceView.dragSourceDelegate = self
}
}
extension ViewController: NSDraggingSource {
//返回拖放操作类型
func draggingSession(_ session: NSDraggingSession, sourceOperationMaskFor context: NSDraggingContext) -> NSDragOperation {
if (context == .outsideApplication){
return .copy
}
else{
return .generic
}
}
//开始拖放代理回调
func draggingSession(_ session: NSDraggingSession, willBeginAt screenPoint: NSPoint) {
print("draggingSession beginAt \(screenPoint)")
}
//拖放鼠标移动时的代理回调
func draggingSession(_ session: NSDraggingSession, movedTo screenPoint: NSPoint) {
print("draggingSession movedTo \(screenPoint)")
}
//结束拖放代理回调
func draggingSession(_ session: NSDraggingSession, endedAt screenPoint: NSPoint, operation: NSDragOperation) {
print("draggingSession endedAt \(screenPoint)")
}
}
I am dragging an image to the desktop through the above code, failed, help
Dear Experts,
I created a SwiftUI View (in a UIKit based project) whose objective is to display a short animation in the front of the user screen. I developed it 8 month ago in XCode 15 for iOS 17, no problems.
But since iOS 18, I can observe huge lags on my animation only in Release app. The problem is not present in Debug app.
I don't understand why this problem occurs, the animation is quite simple, it's just an offset deplacement.
I tried many thing like:
Show the animation with a UINavigationController
Show the animation with a UIWindow
Move the view with .position
Remove the GeometryReader
All other animation
withAnimation and .animation
Task and DispatchQueue
Etc...
I found that the laggy animation occurs when I set the Optimization Level for the Swift Compiler - Code Generation to Optimize for Speed [-O]. That's very strange because we had this option on Release for iOS 17 and we had no lags...
I can share to you a Sample Repository with the configuration we have. https://github.com/Thibma/sample-animation-swiftui
Today the only option I used is to develop this feature in UIKit but it's too bad to skip the SwiftUI opportunity. :/
If you have any ideas to resolve this, I take !
Thank you !
xcode16,iphone16,iOS 自定义navigationItemLeftBar,设置 navigationController?.interactivePopGestureRecognizer?.delegate = self,侧划返回一半,点击屏幕,界面卡死。
18系统之前的手机,或者非iphone16的手机没有问题。
Hello everyone,
I've been having a bit of trouble with the .symbolRenderingMode(_:) modifier.
When trying to apply it to a single button in a toolbar, it does not work at all. The symbol is always rendered as monochrome.
However, I've realised that with this little hack I can achieve the expected results, but this is not ideal.
.toolbar {
HStack {
Button("", action: {}) // The hack
Button("Button", systemImage: "line.3.horizontal.decrease.circle.fill", action: {})
.symbolRenderingMode(.hierarchical)
.foregroundStyle(.blue)
}
}
I've submitted a bug report (FB16129223) but in the meantime, is this my only solution ?
Side note: the foregroundStyle(_:) modifier is ignored as well.
Hello, and an early "Merry Christmas" to all,
I'm building a SwiftUI app, and one of my Views is a fullscreen UIViewRepresentable (SpriteView) beneath a SwiftUI interface.
Whenever the user interacts with any SwiftUI element, the UIView registers a hit in touchesBegan(). For example, my UIView has logic for pinching (not implemented via UIGestureRecognizer), so whenever the user holds down a SwiftUI element while touching the UIView, that counts as two touches to the UIView which invokes the pinching logic.
Things I've tried to block SwiftUI from passing the gesture down to the UIView:
Adding opaque elements beneath control elements
Adding gestures to the elements above
Adding gesture masks to the gestures above
Converting eligible elements to Buttons (since those seem immune)
Adding SpriteViews beneath those elements to absorb gestures
So far nothing has worked. As long as the UIView is beneath SwiftUI elements, any interactions with those elements will be registered as a hit.
The obvious solution is to track each SwiftUI element's size and coordinates with respect to the UIView's coordinate space, then use exclusion areas, but this is both a pain and expensive, and I find it hard to believe this is the best fix for such a seemingly basic problem.
I'm probably overlooking something basic, so any suggestions will be greatly appreciated
Hi all,
Is there way to check the status of multi-stage text input in the TextField of SwiftUI?
I am essentially trying to detect if the user is entering some text with multi-stage text input method right now. (e.g., Japanese, Chinese, etc).
TextField("Search", text: $searchText)
.onKeyPress(keys: [.upArrow, .downArrow]) { event in
if ....some condition here... {
// ignore up/down keys when multi-stage input
return .ignored
}
else {
// do some special key handling
// when multi-stage input is not running
return .handled
}
}
Multi-stage text input uses up/down keys to choose words from candidates, so I don't want to handle the keys when it is happening.
Topic:
UI Frameworks
SubTopic:
SwiftUI
I'm trying to achieve a specific UI design in SwiftUI where the bottom section of my List has a different background color than the top section. For example in the Medications portion of the Health app, the "Your Medications" Section has a different background than the top "Log" Section. How do I achieve this?:
Here some example code. I wonder if I am supposed to use two Lists instead. If I use two Lists though and nest it in a ScrollView, the height of the lists needs to be specified. I am working with dynamic content, though so I don't think that is ideal.
class ProtocolMedication {} // Example model
struct HomeView: View {
@Query private var protocolMedications: [ProtocolMedication]
var body: some View {
NavigationStack {
List {
// Upper sections with default background
Section {
Text("Content 1")
} header: {
Text("Log")
}
// Bottom section that needs different background
Section {
ForEach(protocolMedications) { medication in
Text(medication.name)
}
} header: {
Text("Your Medications")
}
}
.listStyle(.insetGrouped)
}
}
}
I have a very simple SwiftUI app, works fine on iOS, crashes on macOS:
struct ContentView: View
{
@State var testStr: String = ""
@State var selection: TextSelection? = nil
var body: some View
{
VStack
{
TextField("Test", text: $testStr, selection: $selection)
.onChange(of: selection) {print("selection changed")}
}
.padding()
}
}
• Start app, write something in the TextField and move the cursor around.
iOS: "selection changed"
Mac: nothing (Bug ?)
• double click on some word
both Mac and iOS: "selection changed"
• write some more in the TextField
iOS: selection changed
Mac: crash
Any idea what I am doing wrong?
Gerriet.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Hello!
Is there a way to perform an action before alert (no matter which) appears and sheet (no matter which) opens? Perhaps, system event or something like this.
When the APP is in the background, using AccessorySetupKit, calling showPicker is invalid. When I tested it before, it was valid on iOS 18.0, but it is invalid after updating to iOS 18.1.1. Is this a bug? Will it be fixed later?
Topic:
UI Frameworks
SubTopic:
UIKit