In iOS18, Not able to use the UITabBarControllerDelegate.tabBarController(:didSelectTab:previousTab:) function. Since it have duplicate parameter name for didselectTab and previousTab , we're getting Invalid redeclaration of 'tab' error.
UIKit
RSS for tagConstruct and manage graphical, event-driven user interfaces for iOS or tvOS apps using UIKit.
Posts under UIKit tag
200 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
Hi Team,
We are facing crash in CAMediaTimingCopyRenderTiming for production users. And we are unable to trace the crash.
Below is the crash stack trace -
Crashed: com.apple.main-thread
0 QuartzCore 0x14b9c CAMediaTimingCopyRenderTiming + 660
1 QuartzCore 0xfa9c -[CAAnimation _setCARenderAnimation:layer:] + 64
2 QuartzCore 0x146e4 -[CAAnimationGroup _copyRenderAnimationForLayer:] + 356
3 QuartzCore 0x12f3c CA::Layer::commit_animations(CA::Transaction*, double ()(CA::Layer, double, void*), void ()(CA::Layer, CA::Render::Animation*, void*), void ()(CA::Layer, __CFString const*, void*), CA::Render::TimingList* ()(CA::Layer, void*), void*) + 688
4 QuartzCore 0x277c invocation function for block in CA::Context::commit_transaction(CA::Transaction*, double, double*) + 176
5 QuartzCore 0x482bc CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 384
6 QuartzCore 0x48244 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 264
7 QuartzCore 0x48244 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 264
8 QuartzCore 0x48244 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 264
9 QuartzCore 0x48244 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 264
10 QuartzCore 0x48244 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 264
11 QuartzCore 0x48244 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 264
12 QuartzCore 0x48244 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 264
13 QuartzCore 0x48244 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 264
14 QuartzCore 0x48244 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 264
15 QuartzCore 0x48244 CA::Layer::commit_if_needed(CA::Transaction*, void (CA::Layer*, unsigned int, unsigned int) block_pointer) + 264
16 QuartzCore 0x2e078 CA::Context::commit_transaction(CA::Transaction*, double, double*) + 6224
17 QuartzCore 0x59dc0 CA::Transaction::commit() + 644
18 QuartzCore 0x44dbc CA::Transaction::flush_as_runloop_observer(bool) + 84
19 CoreFoundation 0x898e8 CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 32
20 CoreFoundation 0x1951c __CFRunLoopDoObservers + 552
21 CoreFoundation 0x75214 __CFRunLoopRun + 1004
22 CoreFoundation 0x79d20 CFRunLoopRunSpecific + 584
23 GraphicsServices 0x1998 GSEventRunModal + 160
24 UIKitCore 0x371448 -[UIApplication _run] + 868
25 UIKitCore 0x3710c0 UIApplicationMain + 312
26 SwiftUI 0x183c68 OUTLINED_FUNCTION_895 + 2184
27 SwiftUI 0xfdf1c block_copy_helper.1 + 452
28 SwiftUI 0xeaf6c OUTLINED_FUNCTION_901 + 2312
29 Evie Ring 0x2dd20c main + 10 (MovanoRingApp.swift:10)
30 ??? 0x1c7724344 (Missing)
ViewControllers for the 8th and higher tabs are not displayed in the elevated Tab Bar. However, I am able to select these tabs both in the Tab Bar and the side bar.
func setTabs(){
let colors = [UIColor.red,.systemGray6,.green,.systemMint,.cyan,.yellow,.blue,.magenta]
var tabs = [UITab]()
let range = 0...10
for index in range {
if #available(iOS 18.0, *) {
let tab = UITab(title: "Tab_\(index)", image: UIImage(systemName: "globe"), identifier: "tab__\(index)", viewControllerProvider: {tab in
let vc = UIViewController()
vc.view.backgroundColor = colors[index%colors.count]
return vc
})
tabs.append(tab)
}
}
tabbarController.setTabs(tabs, animated: true)
}
I want to achieve Fold animation when the user scrolls UICollectionView. I have UICollectionView with full-screen size cell and vertically scrolling with paging enabled. For that I've created sub-class of UICollectionViewFlowLayout which is as described below.
class FoldingFlowLayout: UICollectionViewFlowLayout {
private let logger = Logger(subsystem: bundleIdentifier, category: "FlowLayout")
override func prepare() {
super.prepare()
scrollDirection = .vertical
minimumLineSpacing = 0
minimumInteritemSpacing = 0
}
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
let attributes = super.layoutAttributesForElements(in: rect)
attributes?.forEach { attribute in
transformLayoutAttributes(attribute)
}
return attributes
}
override func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool {
return true
}
private func transformLayoutAttributes(_ attributes: UICollectionViewLayoutAttributes) {
guard let collectionView = collectionView else { return }
let contentOffsetY = collectionView.contentOffset.y
let cellOffsetY = attributes.frame.origin.y - contentOffsetY
let cellHeight = attributes.frame.height
var transform = CATransform3DIdentity
transform.m34 = -1.0 / 500.0 // Apply perspective
if cellOffsetY < cellHeight && cellOffsetY > -cellHeight {
let angle = (cellOffsetY / cellHeight) * .pi / 2
transform = CATransform3DRotate(transform, angle, -1, 0, 0)
attributes.transform3D = transform
attributes.alpha = 1.0 - (abs(cellOffsetY) / cellHeight)
} else {
attributes.transform3D = CATransform3DIdentity
attributes.alpha = 1.0
}
}
}
But this is not working as I expected. I want to create replica of this kind of animation.
What am I missing here?
I want to convert CGPoint into SCNVector3. I am using ARFaceTrackingConfiguration for face tracking.
Below is my code to convert SCNVector3 to CGPoint
let point = faceAnchor.verticeAndProjection(to: sceneView, facePoint: faceAnchor.geometry.vertices[0])
print(point, faceAnchor.geometry.vertices[0])
which prints below values
CGPoint = (350.564453125, 643.4456787109375)
SIMD3<Float>(0.014480735, 0.01397189, 0.04508282)
extension ARFaceAnchor{
// struct to store the 3d vertex and the 2d projection point
struct VerticesAndProjection {
var vertex: SIMD3<Float>
var projected: CGPoint
}
// return a struct with vertices and projection
func verticeAndProjection(to view: ARSCNView, facePoint: Int) -> CGPoint{
let point = SCNVector3(geometry.vertices[facePoint])
let col = SIMD4<Float>(SCNVector4())
let pos = SIMD4<Float>(SCNVector4(point.x, point.y, point.z, 1))
let pworld = transform * simd_float4x4(col, col, col, pos)
let vect = view.projectPoint(SCNVector3(pworld.position.x, pworld.position.y, pworld.position.z))
let p = CGPoint(x: CGFloat(vect.x), y: CGFloat(vect.y))
return p
}
}
extension matrix_float4x4 {
/// Get the position of the transform matrix.
public var position: SCNVector3 {
get{
return SCNVector3(self[3][0], self[3][1], self[3][2])
}
}
}
Now i want to convert same CGPoint to SCNVector3.
I tried using below code but it is not giving expected values, which is SIMD3(0.014480735, 0.01397189, 0.04508282)
let projectedOrigin = sceneView.projectPoint(SCNVector3Zero)
let unproject = sceneView.unprojectPoint(SCNVector3(point.x, point.y, CGFloat(projectedOrigin.z)))
let vector = SCNVector3(unproject.x, unproject.y, unproject.z)
Is there any way to convert CGPoint to SCNVector3? I cannot use hitTest because this CGPoint is not present on the node. It is present somewhere on the face area.
Hello
I am trying to understand how to properly manage ObservableObject's (ObservedObject inside the SwiftUI View) lifecycle which was created in a view controller as a parent of a SwiftUI view. I have read many posts and rewatched these two videos and I am not still 100% sure
https://developer.apple.com/wwdc20/10040
https://developer.apple.com/wwdc22/10072
So my dilemma boils down to whether it is needed to strongly retain the object by the parent view controller or not. In many sources including the videos it was mentioned that SwiftUI does NOT manage the lifecycle of the ObservedObject.
The SwiftUI view and the model (ObservableObject)
final class MyModel: ObservableObject {
// imagine this is somehow updated form somewhere
@Published var message = ""
}
struct MySwiftUIView: View {
@ObservedObject var myModel: MyModel
var body: some View {
Text("message is \(myModel.message)")
}
}
Option 1: View controller retaining the object
class MyViewController: UIViewController {
let myModel: MyModel // strong reference
let hostingController: UIHostingController<MySwiftUIView>
init() {
myModel = MyModel()
let mySwiftUIView = MySwiftUIView(myModel: myModel)
self.hostingController = UIHostingController(rootView: mySwiftUIView)
super.init(nibName: nil, bundle: nil)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
Option 2: View controller NOT retaining the object
class MyViewController: UIViewController {
let hostingController: UIHostingController<MySwiftUIView>
init() {
let myModel = MyModel() // local retain for the `init` body
let mySwiftUIView = MySwiftUIView(myModel: myModel)
self.hostingController = UIHostingController(rootView: mySwiftUIView)
super.init(nibName: nil, bundle: nil)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
Can i just use Option 2, and not retaining the observable object by the parent view controller or would that cause any issues?
Thank you in advance!
hello We are an input method app,and the crashes mainly occur on the keyboard,Our project collects crashes on Firebase,It is difficult to analyze effective information from the crash stack and we cannot reproduce this crash [_UIViewServiceViewControllerOperator __createViewControllerWithOptions:completionBlock:] + 5116 (UIViewServiceViewControllerOperator.m:2893], Here is our detailed stack link:https://developer.apple.com/forums/content/attachment/172099dc-145c-4195-9423-066e3fa87111
thanks!
Distributor ID: com.apple.AppStore
Hardware Model: iPhone12,1
Process: MyKBIntl [11 728]
Path: /private/var/containers/Bundle/Application/0405842D-F6FD-41DD-AF1C-A3F9339F604D/***
Identifier: com.***.MyIntl.MyKBIntl
Version: 4.32.1 (984)
AppVariant: 1:iPhone12,1:15
Code Type: ARM-64 (Native)
Role: Background
Parent Process: launchd [1]
Coalition: com.***.MyIntl.MyKBIntl [2439]
Date/Time: 2024-07-24 01:29:22.7850 +0700
Launch Time: 2024-07-24 01:29:21.9843 +0700
OS Version: iPhone OS 17.5.1 (21F90)
Release Type: User
Baseband Version: 5.00.00
Report Version: 104
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Termination Reason: SIGNAL 6 Abort trap: 6
Terminating Process: MyKBIntl [11728]
Triggered by Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x19508cf20 __exceptionPreprocess + 164 (NSException.m:249)
1 libobjc.A.dylib 0x18cf42018 objc_exception_throw + 60 (objc-exception.mm:356)
2 CoreFoundation 0x19518b6dc +[NSException raise:format:] + 112 (NSException.m:0)
3 UIKitCore 0x197d9c9cc -[_UIAppearanceRecorder _applyCustomizations] + 2376 (UIAppearance.m:2642)
4 UIKitCore 0x1984a38a8 UIViewServiceUpdateAppearanceWithSerializedRepresentations + 288 (UIViewServiceAppearance.m:50)
5 UIKitCore 0x198498acc -[_UIViewServiceViewControllerOperator __createViewControllerWithOptions:completionBlock:] + 5116 (UIViewServiceViewControllerOperator.m:2893)
6 CoreFoundation 0x195029814 __invoking___ + 148 (:-1)
7 CoreFoundation 0x195028860 -[NSInvocation invoke] + 428 (NSForwarding.m:3411)
8 CoreFoundation 0x19509f1dc -[NSInvocation invokeWithTarget:] + 64 (NSForwarding.m:3508)
9 UIKitCore 0x1984a7170 -[_UIViewServiceImplicitAnimationDecodingProxy forwardInvocation:] + 136 (UIViewServiceImplicitAnimationCoding.m:76)
10 CoreFoundation 0x195029d60 ___forwarding___ + 976 (NSForwarding.m:3654)
11 CoreFoundation 0x1950298d0 _CF_forwarding_prep_0 + 96 (:-1)
12 CoreFoundation 0x195029814 __invoking___ + 148 (:-1)
13 CoreFoundation 0x195028860 -[NSInvocation invoke] + 428 (NSForwarding.m:3411)
14 CoreFoundation 0x19509f1dc -[NSInvocation invokeWithTarget:] + 64 (NSForwarding.m:3508)
15 UIKitCore 0x198487c58 -[_UIQueueingProxy forwardInvocation:] + 308 (UIQueueingProxy.m:57)
16 CoreFoundation 0x195029d60 ___forwarding___ + 976 (NSForwarding.m:3654)
17 CoreFoundation 0x1950298d0 _CF_forwarding_prep_0 + 96 (:-1)
18 CoreFoundation 0x195029814 __invoking___ + 148 (:-1)
19 CoreFoundation 0x195028860 -[NSInvocation invoke] + 428 (NSForwarding.m:3411)
20 CoreFoundation 0x19509f1dc -[NSInvocation invokeWithTarget:] + 64 (NSForwarding.m:3508)
21 CoreFoundation 0x195029d60 ___forwarding___ + 976 (NSForwarding.m:3654)
22 CoreFoundation 0x1950298d0 _CF_forwarding_prep_0 + 96 (:-1)
23 CoreFoundation 0x195029814 __invoking___ + 148 (:-1)
24 CoreFoundation 0x195028860 -[NSInvocation invoke] + 428 (NSForwarding.m:3411)
25 libdispatch.dylib 0x19cf31dd4 _dispatch_client_callout + 20 (object.m:576)
26 libdispatch.dylib 0x19cf3586c _dispatch_block_invoke_direct + 288 (queue.c:511)
27 FrontBoardServices 0x1add06d58 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 52 (FBSSerialQueue.m:285)
28 FrontBoardServices 0x1add06cd8 -[FBSMainRunLoopSerialQueue _targetQueue_performNextIfPossible] + 240 (FBSSerialQueue.m:309)
29 FrontBoardServices 0x1add06bb0 -[FBSMainRunLoopSerialQueue _performNextFromRunLoopSource] + 28 (FBSSerialQueue.m:322)
30 CoreFoundation 0x19505f834 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28 (CFRunLoop.c:1957)
31 CoreFoundation 0x19505f7c8 __CFRunLoopDoSource0 + 176 (CFRunLoop.c:2001)
32 CoreFoundation 0x19505d298 __CFRunLoopDoSources0 + 244 (CFRunLoop.c:2038)
33 CoreFoundation 0x19505c484 __CFRunLoopRun + 828 (CFRunLoop.c:2955)
34 CoreFoundation 0x19505bcd8 CFRunLoopRunSpecific + 608 (CFRunLoop.c:3420)
35 GraphicsServices 0x1d9f0c1a8 GSEventRunModal + 164 (GSEvent.c:2196)
36 UIKitCore 0x19769490c -[UIApplication _run] + 888 (UIApplication.m:3713)
37 UIKitCore 0x1977489d0 UIApplicationMain + 340 (UIApplication.m:5303)
38 libxpc.dylib 0x1f1f3f2c4 _xpc_objc_uimain + 224 (main.m:188)
39 libxpc.dylib 0x1f1f3f0c0 _xpc_objc_main + 108 (main.m:222)
40 libxpc.dylib 0x1f1f4171c _xpc_main + 64 (init.c:1294)
41 libxpc.dylib 0x1f1f418fc xpc_main + 64 (init.c:1377)
42 Foundation 0x19403640c -[NSXPCListener resume] + 312 (NSXPCListener.m:471)
43 PlugInKit 0x1c1389e68 -[PKService runUsingServiceListener:] + 364 (PKService.m:219)
44 PlugInKit 0x1c1389cf4 -[PKService run] + 20 (PKService.m:185)
45 PlugInKit 0x1c13899b0 +[PKService main] + 524 (PKService.m:126)
46 PlugInKit 0x1c138a1c4 +[PKService _defaultRun:arguments:] + 16 (PKService.m:265)
47 ExtensionFoundation 0x1a40bdbf0 EXExtensionMain + 288 (EXExtensionMain.m:0)
48 Foundation 0x1940c280c NSExtensionMain + 204 (NSExtensionMain.m:21)
49 dyld 0x1b870de4c start + 2240 (dyldMain.cpp:1298)
Thread 0 name:
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x00000001de14742c __pthread_kill + 8 (:-1)
1 libsystem_pthread.dylib 0x00000001f1ee6c0c pthread_kill + 268 (pthread.c:1721)
2 libsystem_c.dylib 0x000000019cfeaba0 abort + 180 (abort.c:118)
3 libc++abi.dylib 0x00000001f1e04ca4 abort_message + 132 (abort_message.cpp:78)
4 libc++abi.dylib 0x00000001f1df4e5c demangling_terminate_handler()
// Word limit, you can view our detailed stack
I'm getting a crash report from our custom keyboard extension that involves UIKit. [_UIViewServiceViewControllerOperator __createViewController:withContextToken...
Can someone see what's going on in this report? Perhaps someone that know what's at (UIViewServiceViewControllerOperator.m:2893) , thanks!
Here is the full stack:https://developer.apple.com/forums/content/attachment/cc75d557-40aa-4023-beab-a2efc7a3901d
Distributor ID: com.apple.AppStore
Hardware Model: iPhone12,1
Process: MyKBIntl [11 728]
Path: /private/var/containers/Bundle/Application/0405842D-F6FD-41DD-AF1C-A3F9339F604D/***
Identifier: com.***.MyIntl.MyKBIntl
Version: 4.32.1 (984)
AppVariant: 1:iPhone12,1:15
Code Type: ARM-64 (Native)
Role: Background
Parent Process: launchd [1]
Coalition: com.***.MyIntl.MyKBIntl [2439]
Date/Time: 2024-07-24 01:29:22.7850 +0700
Launch Time: 2024-07-24 01:29:21.9843 +0700
OS Version: iPhone OS 17.5.1 (21F90)
Release Type: User
Baseband Version: 5.00.00
Report Version: 104
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Termination Reason: SIGNAL 6 Abort trap: 6
Terminating Process: MyKBIntl [11728]
Triggered by Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x19508cf20 __exceptionPreprocess + 164 (NSException.m:249)
1 libobjc.A.dylib 0x18cf42018 objc_exception_throw + 60 (objc-exception.mm:356)
2 CoreFoundation 0x19518b6dc +[NSException raise:format:] + 112 (NSException.m:0)
3 UIKitCore 0x197d9c9cc -[_UIAppearanceRecorder _applyCustomizations] + 2376 (UIAppearance.m:2642)
4 UIKitCore 0x1984a38a8 UIViewServiceUpdateAppearanceWithSerializedRepresentations + 288 (UIViewServiceAppearance.m:50)
5 UIKitCore 0x198498acc -[_UIViewServiceViewControllerOperator __createViewControllerWithOptions:completionBlock:] + 5116 (UIViewServiceViewControllerOperator.m:2893)
6 CoreFoundation 0x195029814 __invoking___ + 148 (:-1)
7 CoreFoundation 0x195028860 -[NSInvocation invoke] + 428 (NSForwarding.m:3411)
8 CoreFoundation 0x19509f1dc -[NSInvocation invokeWithTarget:] + 64 (NSForwarding.m:3508)
9 UIKitCore 0x1984a7170 -[_UIViewServiceImplicitAnimationDecodingProxy forwardInvocation:] + 136 (UIViewServiceImplicitAnimationCoding.m:76)
10 CoreFoundation 0x195029d60 ___forwarding___ + 976 (NSForwarding.m:3654)
11 CoreFoundation 0x1950298d0 _CF_forwarding_prep_0 + 96 (:-1)
12 CoreFoundation 0x195029814 __invoking___ + 148 (:-1)
13 CoreFoundation 0x195028860 -[NSInvocation invoke] + 428 (NSForwarding.m:3411)
14 CoreFoundation 0x19509f1dc -[NSInvocation invokeWithTarget:] + 64 (NSForwarding.m:3508)
15 UIKitCore 0x198487c58 -[_UIQueueingProxy forwardInvocation:] + 308 (UIQueueingProxy.m:57)
16 CoreFoundation 0x195029d60 ___forwarding___ + 976 (NSForwarding.m:3654)
17 CoreFoundation 0x1950298d0 _CF_forwarding_prep_0 + 96 (:-1)
18 CoreFoundation 0x195029814 __invoking___ + 148 (:-1)
19 CoreFoundation 0x195028860 -[NSInvocation invoke] + 428 (NSForwarding.m:3411)
20 CoreFoundation 0x19509f1dc -[NSInvocation invokeWithTarget:] + 64 (NSForwarding.m:3508)
21 CoreFoundation 0x195029d60 ___forwarding___ + 976 (NSForwarding.m:3654)
22 CoreFoundation 0x1950298d0 _CF_forwarding_prep_0 + 96 (:-1)
23 CoreFoundation 0x195029814 __invoking___ + 148 (:-1)
24 CoreFoundation 0x195028860 -[NSInvocation invoke] + 428 (NSForwarding.m:3411)
25 libdispatch.dylib 0x19cf31dd4 _dispatch_client_callout + 20 (object.m:576)
26 libdispatch.dylib 0x19cf3586c _dispatch_block_invoke_direct + 288 (queue.c:511)
27 FrontBoardServices 0x1add06d58 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 52 (FBSSerialQueue.m:285)
28 FrontBoardServices 0x1add06cd8 -[FBSMainRunLoopSerialQueue _targetQueue_performNextIfPossible] + 240 (FBSSerialQueue.m:309)
29 FrontBoardServices 0x1add06bb0 -[FBSMainRunLoopSerialQueue _performNextFromRunLoopSource] + 28 (FBSSerialQueue.m:322)
30 CoreFoundation 0x19505f834 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28 (CFRunLoop.c:1957)
31 CoreFoundation 0x19505f7c8 __CFRunLoopDoSource0 + 176 (CFRunLoop.c:2001)
32 CoreFoundation 0x19505d298 __CFRunLoopDoSources0 + 244 (CFRunLoop.c:2038)
33 CoreFoundation 0x19505c484 __CFRunLoopRun + 828 (CFRunLoop.c:2955)
34 CoreFoundation 0x19505bcd8 CFRunLoopRunSpecific + 608 (CFRunLoop.c:3420)
35 GraphicsServices 0x1d9f0c1a8 GSEventRunModal + 164 (GSEvent.c:2196)
36 UIKitCore 0x19769490c -[UIApplication _run] + 888 (UIApplication.m:3713)
37 UIKitCore 0x1977489d0 UIApplicationMain + 340 (UIApplication.m:5303)
38 libxpc.dylib 0x1f1f3f2c4 _xpc_objc_uimain + 224 (main.m:188)
39 libxpc.dylib 0x1f1f3f0c0 _xpc_objc_main + 108 (main.m:222)
40 libxpc.dylib 0x1f1f4171c _xpc_main + 64 (init.c:1294)
41 libxpc.dylib 0x1f1f418fc xpc_main + 64 (init.c:1377)
42 Foundation 0x19403640c -[NSXPCListener resume] + 312 (NSXPCListener.m:471)
43 PlugInKit 0x1c1389e68 -[PKService runUsingServiceListener:] + 364 (PKService.m:219)
44 PlugInKit 0x1c1389cf4 -[PKService run] + 20 (PKService.m:185)
45 PlugInKit 0x1c13899b0 +[PKService main] + 524 (PKService.m:126)
46 PlugInKit 0x1c138a1c4 +[PKService _defaultRun:arguments:] + 16 (PKService.m:265)
47 ExtensionFoundation 0x1a40bdbf0 EXExtensionMain + 288 (EXExtensionMain.m:0)
48 Foundation 0x1940c280c NSExtensionMain + 204 (NSExtensionMain.m:21)
49 dyld 0x1b870de4c start + 2240 (dyldMain.cpp:1298)
// Here too long is truncated, you can see the full stack
EOF
I wanted to experiment a little using UINavigationController with SwiftUI App Lifecycle
I created a Custom Navigation Controller named JDNavigationController. It does not do much other than having the @Observable macro
public struct NavigationControllerStack<Content: View>: UIViewControllerRepresentable {
private let initialView: () -> Content
@State private var controller = JDNavigationController()
public init(content: @escaping () -> Content) {
self.initialView = content
}
public func makeUIViewController(context: Context) -> JDNavigationController {
let viewController = self.initialView()
.environment(self.controller)
.viewController
self.controller.viewControllers = [
viewController
]
return controller
}
public func updateUIViewController(_ uiViewController: JDNavigationController, context: Context) {
}
public typealias UIViewControllerType = JDNavigationController
}
when I check, the functionality of the navigation controller works as expected, however, I can't for the life of me to change the background color of the status bar.
#Preview {
NavigationControllerStack {
ZStack {
Color.purple
.ignoresSafeArea(.all)
VStack {
Text("somethign")
}
}
}
}
I have tried
Using the appearance functions
Creating a Custom View Controller, and in that view controller I tried using a Hosting Controller by adding the hosting controller as a child and
setting hostingController.view.insetsLayoutMarginsFromSafeArea = false
using the toolbar modifiers from SwiftUI View
none seems to work.
I opened the View Debugger it looks like the white portion comes from the UIHosting Controller but I am not sure what I can do to fix it
I have had a suspicious crash in my app for a long time. I'm 95% using SwiftUI and have to use only one UIKit view that I embed into SwiftUI in my app.
I don't understand why my app crashes when the CALayer position is set to Nan because I don't reference layers at all, including that UIKit view.
Any ideas why it may happen and how can I reproduce it?
Fatal Exception: CALayerInvalidGeometry
CALayer position contains NaN: [nan nan]. Layer: <CAShapeLayer:0x303cd9600; position = CGPoint (0 0); bounds = CGRect (0 0; 0 0); delegate = _NoAnimationDelegate; allowsGroupOpacity = YES; anchorPoint = CGPoint (0 0); >
Fatal Exception: CALayerInvalidGeometry
0 CoreFoundation 0x83f20 __exceptionPreprocess
1 libobjc.A.dylib 0x16018 objc_exception_throw
2 CoreFoundation 0x1826dc -[NSException initWithCoder:]
3 QuartzCore 0x7b28 CA::Layer::set_position(CA::Vec2<double> const&, bool)
4 QuartzCore 0x7a58 -[CALayer setPosition:]
5 SwiftUI 0x1a131d4 objectdestroy.10Tm
6 SwiftUI 0x1a12ab4 objectdestroy.10Tm
7 SwiftUI 0x281590 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
8 SwiftUI 0x280c0c -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
9 SwiftUI 0x28083c -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
10 SwiftUI 0x27eaf8 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
11 SwiftUI 0x27e2c0 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
12 SwiftUI 0x27c6b0 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
13 SwiftUI 0x27bba8 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
14 SwiftUI 0x27c480 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
15 SwiftUI 0x27bba8 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
16 SwiftUI 0x27c480 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
17 SwiftUI 0x27bba8 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
18 SwiftUI 0x27c480 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
19 SwiftUI 0x27bba8 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
20 SwiftUI 0x27e408 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
21 SwiftUI 0x27c6b0 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
22 SwiftUI 0x27bba8 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
23 SwiftUI 0x27c480 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
24 SwiftUI 0x27bba8 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
25 SwiftUI 0x1a34a8 get_witness_table 7SwiftUI4ViewRzAA7GestureRd__r__lAA15ModifiedContentVyxAA03AddD8ModifierVyqd__GGAaBHPxAaBHD1__AhA0cH0HPyHCHCTm
26 SwiftUI 0x1a323c get_witness_table 7SwiftUI4ViewRzAA7GestureRd__r__lAA15ModifiedContentVyxAA03AddD8ModifierVyqd__GGAaBHPxAaBHD1__AhA0cH0HPyHCHCTm
27 SwiftUI 0x1a2c54 get_witness_table 7SwiftUI4ViewRzAA7GestureRd__r__lAA15ModifiedContentVyxAA03AddD8ModifierVyqd__GGAaBHPxAaBHD1__AhA0cH0HPyHCHCTm
28 SwiftUI 0x1a2ba4 get_witness_table 7SwiftUI4ViewRzAA7GestureRd__r__lAA15ModifiedContentVyxAA03AddD8ModifierVyqd__GGAaBHPxAaBHD1__AhA0cH0HPyHCHCTm
29 SwiftUI 0x1a2ab0 get_witness_table 7SwiftUI4ViewRzAA7GestureRd__r__lAA15ModifiedContentVyxAA03AddD8ModifierVyqd__GGAaBHPxAaBHD1__AhA0cH0HPyHCHCTm
30 SwiftUI 0x1a2a78 get_witness_table 7SwiftUI4ViewRzAA7GestureRd__r__lAA15ModifiedContentVyxAA03AddD8ModifierVyqd__GGAaBHPxAaBHD1__AhA0cH0HPyHCHCTm
31 SwiftUI 0x1a2a40 get_witness_table 7SwiftUI4ViewRzAA7GestureRd__r__lAA15ModifiedContentVyxAA03AddD8ModifierVyqd__GGAaBHPxAaBHD1__AhA0cH0HPyHCHCTm
32 SwiftUI 0x1a2930 get_witness_table 7SwiftUI4ViewRzAA7GestureRd__r__lAA15ModifiedContentVyxAA03AddD8ModifierVyqd__GGAaBHPxAaBHD1__AhA0cH0HPyHCHCTm
33 UIKitCore 0x95540 +[UIView(Animation) performWithoutAnimation:]
34 SwiftUI 0x2686ec -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
35 SwiftUI 0x2656d8 -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
36 SwiftUI 0x263d7c -[UIScrollView(SwiftUI) _swiftui_adjustsContentInsetWhenScrollDisabled]
37 SwiftUI 0x18eedc OUTLINED_FUNCTION_519
38 SwiftUI 0x18e8d8 OUTLINED_FUNCTION_519
39 SwiftUI 0x18e768 OUTLINED_FUNCTION_519
40 QuartzCore 0xd0ecc CA::Display::DisplayLinkItem::dispatch_(CA::SignPost::Interval<(CA::SignPost::CAEventCode)835322056>&)
41 QuartzCore 0xcf230 CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long)
42 QuartzCore 0xcedd0 CA::Display::DisplayLink::dispatch_deferred_display_links(unsigned int)
43 UIKitCore 0xb776c _UIUpdateSequenceRun
44 UIKitCore 0xb73b0 schedulerStepScheduledMainSection
45 UIKitCore 0xb8254 runloopSourceCallback
46 CoreFoundation 0x56834 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
47 CoreFoundation 0x567c8 __CFRunLoopDoSource0
48 CoreFoundation 0x54298 __CFRunLoopDoSources0
49 CoreFoundation 0x53484 __CFRunLoopRun
50 CoreFoundation 0x52cd8 CFRunLoopRunSpecific
51 GraphicsServices 0x11a8 GSEventRunModal
52 UIKitCore 0x40a90c -[UIApplication _run]
53 UIKitCore 0x4be9d0 UIApplicationMain
54 SwiftUI 0x3f4148 OUTLINED_FUNCTION_283
55 SwiftUI 0x3a0714 OUTLINED_FUNCTION_283
56 SwiftUI 0x3ac4d0 OUTLINED_FUNCTION_283
57 VerkadaPass 0xd1b4 main (MyApp.swift)
58 ??? 0x1ca1dde4c (Missing)
Hello,
my app sometimes has this super weird issue with scroll in a horizontal section (see the GIF below). The thing is, I have ever spotted it only in this third section and not the two sections above it.
All have the same compositional collection view layout and are powered by the diffable data source. I reexamined the item definition and I don't think this could be a case of hash values being same and hence confusing the collection view.
It also seems to happen only to these first items. It is not frequent but on my own device I have seen it many times so far. The problem always seems to manifest in similar manner.
Anyone seen this? I am hoping that maybe someone will recognize the problem from the GIF.
I made an extension with a UIView that takes a SwiftUI view, gets its UIView, and then adds it as a subview. But now the subview isn't receiving any touches and idk how to fix that. I've already tried point(inside:with:) but it doesn't seem to work. I've also tried forwarding the touches from touchesBegan, touchesMoved, etc., but that didn't work either.
Any help or advice would be greatly appreciated!
Extension with the UIView:
// Add view modifier to View
extension View {
func transformable() -> some View {
modifier(Transformable())
}
}
// View modifier
struct Transformable: ViewModifier {
func body(content: Content) -> some View {
TransformableUIView(content: content)
}
}
// Wrap UIView
struct TransformableUIView<V>: UIViewRepresentable where V: View {
private var content: V
init(content: V) {
self.content = content
}
func makeUIView(context: Context) -> TransformableView<V> {
TransformableView(content: content)
}
func updateUIView(_ uiView: TransformableView<V>, context: Context) {}
}
// View that handles zoom, pan, and rotate gestures
class TransformableView<V>: UIView, UIGestureRecognizerDelegate where V: View {
private var content: V
private var initialCenter: CGPoint = .zero
private var totalScale: CGFloat = 1.0
private var boundsDidSet = false
required init(content: V) {
self.content = content
super.init(frame: .zero)
self.addSubview(content.uiView)
let panGesture = UIPanGestureRecognizer(target: self, action: #selector(panPiece(_:)))
panGesture.minimumNumberOfTouches = 2
panGesture.maximumNumberOfTouches = 2
panGesture.delegate = self
self.addGestureRecognizer(panGesture)
let scaleGesture = UIPinchGestureRecognizer(target: self, action: #selector(scalePiece(_:)))
scaleGesture.delegate = self
self.addGestureRecognizer(scaleGesture)
let rotateGesture = UIRotationGestureRecognizer(target: self, action: #selector(rotatePiece(_:)))
rotateGesture.delegate = self
self.addGestureRecognizer(rotateGesture)
}
// Position content in center of view
override func layoutSubviews() {
super.layoutSubviews()
// Return if bounds are already set
if boundsDidSet {
return
}
guard let piece = self.subviews.first else { return }
piece.center = CGPoint(x: self.bounds.size.width / 2, y: self.bounds.size.height / 2)
boundsDidSet = true
}
// Function called when pan gesture is recognized
@objc private func panPiece(_ gestureRecognizer: UIPanGestureRecognizer) {
guard let piece = gestureRecognizer.view?.subviews.first else { return }
// Get the changes in the X and Y directions relative to
// the superview's coordinate space.
let translation = gestureRecognizer.translation(in: piece.superview)
if gestureRecognizer.state == .began {
// Save the view's original position.
self.initialCenter = piece.center
}
// Update the position for the .began, .changed, and .ended states
if gestureRecognizer.state != .cancelled {
// Add the X and Y translation to the view's original position.
var newCenter = CGPoint(x: initialCenter.x + translation.x, y: initialCenter.y + translation.y)
// Prevent content from leaving view
newCenter.x = clamp(value: newCenter.x, min: 0, max: self.bounds.width)
newCenter.y = clamp(value: newCenter.y, min: 0, max: self.bounds.height)
piece.center = newCenter
}
else {
// On cancellation, return the piece to its original location.
piece.center = initialCenter
}
}
// Function called when scale gesture is recognized
@objc private func scalePiece(_ gestureRecognizer : UIPinchGestureRecognizer) {
guard let piece = gestureRecognizer.view?.subviews.first else { return }
if gestureRecognizer.state == .began || gestureRecognizer.state == .changed {
// Set min/max zoom
let newScale = clamp(value: totalScale * gestureRecognizer.scale, min: 0.2, max: 20) / totalScale
piece.transform = (piece.transform.scaledBy(x: newScale, y: newScale))
gestureRecognizer.scale = 1.0
totalScale *= newScale
}
}
// Function called when rotate gesture is recognized
@objc private func rotatePiece(_ gestureRecognizer : UIRotationGestureRecognizer) {
guard let piece = gestureRecognizer.view?.subviews.first else { return }
if gestureRecognizer.state == .began || gestureRecognizer.state == .changed {
piece.transform = piece.transform.rotated(by: gestureRecognizer.rotation)
gestureRecognizer.rotation = 0
}
}
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}
func clamp(value: CGFloat, min: CGFloat, max: CGFloat) -> CGFloat {
if value < min {
return min
} else if value > max {
return max
} else {
return value
}
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
Get UIView from SwiftUI View:
// Get UIView from SwiftUI View
extension View {
var uiView: UIView {
UIHostingController(rootView: self).view
}
}
ContentView:
struct ContentView: View {
var body: some View {
CanvasView()
.frame(width: 880, height: 608)
.transformable()
.background(Color.blue)
}
}
I am using NSCollectionLayoutSection.list as follow.
private func layoutConfig() -> UICollectionViewCompositionalLayout {
let layout = UICollectionViewCompositionalLayout { section, layoutEnvironment in
var config = UICollectionLayoutListConfiguration(appearance: .plain)
config.headerMode = .supplementary
config.footerMode = .none
config.showsSeparators = false
config.headerTopPadding = 0
// https://developer.apple.com/forums/thread/759987
let layoutSection = NSCollectionLayoutSection.list(using: config, layoutEnvironment: layoutEnvironment)
layoutSection.interGroupSpacing = 0
layoutSection.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)
if let header = layoutSection.boundarySupplementaryItems.first(where: { $0.elementKind == UICollectionView.elementKindSectionHeader }) {
header.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)
}
return layoutSection
}
return layout
}
We provide our own custom header view and cell item view.
Header View
class HideShowHeader: UICollectionViewListCell {
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func systemLayoutSizeFitting(_ targetSize: CGSize) -> CGSize {
// Ensure the cell fills the width of the collection view
let size = CGSize(
width: targetSize.width,
height: 80
)
print(">>>> size \(size)")
return size
}
}
Cell Item View
class TodoCell: UICollectionViewListCell {
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func systemLayoutSizeFitting(_ targetSize: CGSize) -> CGSize {
// Ensure the cell fills the width of the collection view
let size = CGSize(
width: targetSize.width,
height: 80
)
return size
}
}
We would like to fine-tune the height of header and cell item.
However, override systemLayoutSizeFitting doesn't work.
May I know, when using NSCollectionLayoutSection.list, how to specific header height and cell item height?
Thanks.
Dear Experts,
My app is observing UIPasteboardChangeNotification in order to enable/disable its paste button.
I do not seem to be getting any notifications when other apps copy to the clipboard. For example, if I have my app and Safari in split-screen on my iPad and I copy something in Safari, I don't see the notification. Similarly if I switch to Safari, copy something, and switch back to my app, I do not get the notification either when I'm in the background or when I return to the foreground.
The only time that I see UIPasteboardChangedNotification is when the clipboard is modified by my app itself.
Is this supposed to work? Is there some other way to get notified when the clipboard is changed by another app?
Thanks.
I'm trying to add an SVG image to my launch screen. The SVG image is working fine in the main storyboard also used in a UIImageView, but the launch screen remains completely black; the launch screen is set with white background, so it seems to be completely ignored. When I remove the image from the UIImageView the launch screen is shown with correct background color but of course without the whished image. I can also correctly implement text in the launch screen, the launch screen shows the text and the background color correctly. As soon as I define an image from the asset catalogue for the UIImageView in the launch screen, the launch screen is completely black not showing anything. I tried also with a simple png image-set instead of the SVG image, but still the same issue. How can I implement a SVG image in my launch screen?
Hello,
I have an iOS app that is using SwiftUI but the gesture code is written using UIGestureRecognizer. When I run this app on visionOS using the "Designed for iPad" destination and try to use any of my gestures I see this warning in the console:
Trying to convert coordinates between views that are in different UIWindows, which isn't supported. Use convertPoint:fromCoordinateSpace: instead.
But I don't see any visible problems with the gestures.
I see this warning printed out after the gesture takes place but before any of our gesture methods get kicked off. So now I am wondering if this is something we need to deal with or some internal work that needs to happen in UIKit.
Does anyone have any thoughts on this?
Hello!
I am working on an application with a chat feature. The chat is implemented using a UICollectionView. The content in our chat grows from the bottom and upwards, as is standard (like for instance the Messages app), with the most recent item being shown at the bottom.
We have implemented this using a "hack", flipping the collection view upside-down by using a transform, and flipping the content views of the cells upside down again. This works nicely; the only remaining problem is ensuring that elements are read in the correct order for users with VoiceOver enabled.
Standard behaviour with VoiceOver enabled for collection views is that swiping right moves focus to the next element, while swiping left moves focus to the previous element. Despite the collectionView being inverted (upside-down) swiping right with VoiceOver enabled moves focus to the element above, while swiping left moves focus to the element below. Is there any way to invert this behaviour?
I have looked at subclassing the collection view and overriding accessibilityIncrement and accessibilityDecrement, but it did not have any effect. It seems the standard collection view accessibility container implementation does not call these methods.
Currently, I am using UICollectionViewCompositionalLayout to achieve the following list layout with spacing:
We were thinking of trying out UICollectionLayoutListConfiguration due to its ability to support swipe actions.
We would like to specify the spacing between each item. However, I do not find a way to specify item spacing in UICollectionLayoutListConfiguration.
Does UICollectionLayoutListConfiguration not support item spacing, or have I missed something?
Thanks.
Currently, this is how I implement the drag and move operation:
collectionView.beginInteractiveMovementForItem
collectionView.updateInteractiveMovementTargetPosition
collectionView.endInteractiveMovement
The outcome looks like the following:
However, what I would like to achieve is the ability to customize the view of the "drop" location.
For instance, in the following example, a red line is drawn at the target drop location:
In this example, a transparent rectangle is drawn at the target drop location:
May I know how these apps achieve such an effect?
Thanks.
@interface CallbackClass : NSObject
(void) doSomething:(UIKeyCommand*)keycmd;
(UIKeyCommand*) returnKeyCommand;
@end
@implementation CallbackClass
(void) doSomething:(UIKeyCommand*)keycmd {
NSLog(@"KEY CLICKED");
}
-(UIKeyCommand*) returnKeyCommand {
return [UIKeyCommand keyCommandWithInput:@"a"
modifierFlags:0
action:@selector(doSomething:)];
}
@end
void CppClass::bindKeyCommand() {
CallbackClass* callbackClass = [[CallbackClass alloc] init];
[[UIApplication sharedApplication].keyWindow.rootViewController]
addKeyCommand:[callbackClass returnKeyCommand]];
}
This is objective-c code that is injected into QT application with C++ and Cmake.
Responder chain after executing this code:
Even if this key command is present is in the responder chain i dont have any reaction on click on magic keyboard. When i do this in the pure objective-c but not with with QT, C++, Cmake project.
I Detect key input but only when i add my custom view controller do the subview of QIOSViewController, but then i cany click anything else on my application then.
I want to be able to detect key input or somehow inject a responder into responder chain and still being able to click things on my application.