I have a NSWindow subclass. The window has a custom shape, and thus has a custom contentView which overrides drawRect to draw .
Since the window has a custom shape it cannot use the system provided titlebar.
The problem I'm having is when there are multiple screens, if my window is on the inactive screen (not mainScreen with menu bar) and I move the mouse over to the second monitor and click the window....the menu bar doesn't travel to the screen my app is on after the window is clicked.
This does not happen with any other window. In all other windows, the menu bar moves to the screen once you click a window on that screen. So it appears this is because my window is not using NSWindowStyleMaskTitled. As far as I know, I can't use the system title bar and draw my custom window shape. Abandoning the custom window shape is not an option.
Without going into too many details as to why I care, the menu bar really should travel with first click on my window like other apps.. Is there a way to tell the system (other than using the NSWindowStyleMaskTitled) that clicking on my window should make that screen the "main screen" (bring the menu bar over?
I tried programmatically activating the application, ordering the window to the front, etc. but none of this works. This forces the user to click outside my app window, say on the desktop, to move the menu bar over, which feels wrong.
Thanks in advance if anyone has any suggestions.
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.
Post
Replies
Boosts
Views
Activity
My problem: I tap in one of the TextFields defined below and try to type. After typing a single character, the cursor disappears from the TextField and I need to tap in the field again to enter the next character.
I have the following code:
@Observable
final class Species {
. . .
public var list: [String]
. . .
}
struct SpeciesCapture: View {
@State private var species = Species()
@State var trainingList: [String] = []
var body: some View {
NavigationStack {
VStack(alignment: .leading) {
HStack {
Text("some text")
Spacer()
Button("Add") {
trainingList.append("")
}
}
List {
ForEach($trainingList, id: \.self) { $animal in
TextField("Animal", text: $animal)
.textCase(.lowercase)
}
}
}
.onAppear {
trainingList = species.list
. . .
}
. . . // etc.
}
}
}
It appears that I am continually losing focus. How do I fix this problem?
Xcode 16.0 targeting iOS 18. The behavior appears in both Preview and the Simulator. (Haven't tried it on a physical device).
Now that we are finally able to customize our home screen, can you disable the auto relocation feature? Making it extremely difficult to customize home screen when things are still moving around automatically. Thanks.
I have created a custom logo in the SFSymbols 6.1 app and exported it as SVG.
clock.arrow.trianglehead.clockwise.rotate.90.svg
The icon consists of two layers and I want them to animate by layer. This works for the wiggle effect (the two layers are moving independently), but not for the rotate effect (the logo moves as a whole). Why? This is my code:
let imageView = UIImageView()
imageView.preferredSymbolConfiguration = UIImage.SymbolConfiguration(scale: .large)
imageView.image = UIImage(named: "clock.arrow.trianglehead.clockwise.rotate.90", in: nil, with: nil)
imageView.translatesAutoresizingMaskIntoConstraints = false
let imageView2 = UIImageView()
imageView2.preferredSymbolConfiguration = UIImage.SymbolConfiguration(scale: .large)
imageView2.image = UIImage(named: "clock.arrow.trianglehead.clockwise.rotate.90", in: nil, with: nil)
imageView2.translatesAutoresizingMaskIntoConstraints = false
imageView.addSymbolEffect(.rotate.byLayer, options: .repeat(.continuous));
imageView2.addSymbolEffect(.wiggle.byLayer, options: .repeat(.continuous));
view.addSubview(imageView)
view.addSubview(imageView2)
NSLayoutConstraint.activate([
imageView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
imageView.centerYAnchor.constraint(equalTo: view.centerYAnchor),
imageView2.centerXAnchor.constraint(equalTo: view.centerXAnchor),
imageView2.topAnchor.constraint(equalTo: imageView.bottomAnchor, constant: 40),
])
Hey all,
I am facing a new issue on iOS 18 with ScenePhase and .onChange modifier.
Here's roughly the code:
.onChange(of: scenePhase, initial: true) { old, new in
if new == .active {
doStuff()
}
}
on iOS 17 this was working as expected and triggered when eg. ap was brough from background or user navigated back to view
on ios18 though this code gets triggered constatnly in my case when I eg. navigate to another screen on top of the one with that .onChange. after navigation happens, the onChange is being triggered continuosly and does not stop which causes doStuff() to be called multiple times
I encountered a crash with my SwiftUI app for macOS.
NSInvalidArgumentException: -[MTLIGAccelRenderCommandEncoder setVertexBuffer:offset:attributeStride:atIndex:]: unrecognized selector sent to instance
struct ContentView: View {
@State var text = ""
var body: some View {
TextEditor(text: $text)
}
}
When I run macOS app, console print
NSBundle file:///System/Library/PrivateFrameworks/MetalTools.framework/ principal class is nil because all fallbacks have failed
and I found it crash with TextEditor.
Can somebody help me?
App intent is a powerful framework, we can show any swiftui in the result, but button action is not working in it, I have a table of cards to show in the result and I want to implement some action when user selects each card, Button actions are not working here, what should I do
Hi folks,
i have a swiftui app with a custom view (derived from UIRepresenatble)
in this view i load a scenekit scene and start an animation to rotate an object
this all works!
but when the whole thing gets updated, my custom view gets updated too and the former working animation stops!
Please tell me what i'm doing wrong!
Sincerely,
Wolfi
I am developing an app that supports iOS 15 and later.
Up until iOS 17, the behavior of onDrag and onDrop was as follows:
The item is moved by holding it and dragging it to the onDrop area.
When the item is dropped in the onDrop area, the logic is executed, and simultaneously, the item disappears immediately.
However, in iOS 18 the item remains for about 0.5 to 1.0 seconds before disappearing, even though there is no logic in the onDrop.
Is this the expected behavior, or is it a bug?"
In iOS 18, when navigating from Page A (with a red navigation bar background color) to Page B, and Page B hides the navigation bar, upon returning to Page A, the background color of the navigation bar appears white (seemingly transparent).
The navigation bar background for the share button should be red.
We are currently combining AutoLayout and StackView to structure our cells, and we’re using UICollectionViewCompositionalLayout to set up sections. Additionally, we’re utilizing UICollectionViewDiffableDataSource to manage the data source. On the home screen, we display cells in a multi-section layout.
In the main screen, we support infinite scrolling and use a paging method that fetches 10 items at a time from the API. As we fetch and render more data, the number of displayed cells increases. However, we’ve noticed that as the number of displayed cells grows, the UI freezes during the process of fetching and rendering more data.
We suspect that the issue lies in the configuration of UICollectionViewCompositionalLayout. When data is fetched through paging, the data is applied to the CollectionViewDiffableDataSource, and during the process of displaying it on the screen, the method that configures the UICollectionViewCompositionalLayout layout is called. The problem here is that when 10 cells are displayed on the screen and we fetch more data through paging and add 10 more cells, the layout calculation is redone for all 20 cells. In other words, the UICollectionViewCompositionalLayout layout configuration occurs a total of 20 times.
Because of this, it seems that the UI freezing issue occurs as the number of cells increases.
What steps can we take to resolve this problem? We have attached the relevant code for your reference.
private lazy var collectionView = UICollectionView(
frame: .zero,
collectionViewLayout: self.createCollectionViewLayout()
)
private func createCollectionViewLayout() -> UICollectionViewLayout {
let layout = UICollectionViewCompositionalLayout { [weak self] sectionIndex, _ in
guard let self, self.dataSource.snapshot().sectionIdentifiers.isEmpty == false
else { return LayoutProvider.emptySection() }
private func applyRefreshSnapshot(with sections: [PlateViewSection]) {
var snapshot = self.dataSource.snapshot()
snapshot.deleteAllItems()
snapshot.appendSections(sections)
sections.forEach { section in
snapshot.appendItems(section.items, toSection: section)
}
self.dataSource.apply(snapshot, animatingDifferences: false)
}
let sectionIdentifier = self.dataSource.snapshot().sectionIdentifiers[safe: sectionIndex]
let analyticsScreen = self.payload.analyticsScreen
switch sectionIdentifier?.module {
case let .tabOutlined(_, reactor):
if self.tabOutlinedView == nil {
let tabOutlinedView = self.dependency.tabOutlinedViewFactory.create(
payload: .init(
reactor: reactor,
collectionView: self.collectionView,
analyticsScreen: analyticsScreen,
currentDisplayDepthObserver: .init { event in
guard let depth = event.element else { return }
self.currentLayoutHeaderTabDepth = depth
},
selectedTabItemObserver: .init { [weak self] event in
guard let (tab, isPrimaryTabClick) = event.element else { return }
var queryParams: [String: String]?
if isPrimaryTabClick == false {
guard let currentState = self?.reactor?.currentState else { return }
let currentSelectedQueryParams = self?.dependency.userDefaults
.dictionary(forKey: Keys.PlateParamsKeys.brandQueryParams) as? [String: String]
queryParams = currentSelectedQueryParams ?? currentState.defaultQueryParams
}
self?.scrollCollectionViewToTop()
self?.collectionView.viewWithTag(
QueryToggleModuleCell.Metric.optionsMenuViewTag
)?.removeFromSuperview()
self?.reactor?.action.onNext(.refreshWithParams(
tabParams: tab?.params,
queryParams: queryParams
))
}
)
)
self.view.addSubview(tabOutlinedView)
tabOutlinedView.snp.makeConstraints { make in
make.top.leading.trailing.equalToSuperview()
}
self.view.layoutIfNeeded()
self.tabOutlinedView = tabOutlinedView
self.tabOutlinedView?.emitInitializeAction()
}
return LayoutProvider.emptySection()
case let .carouselOneRowBrand(module, _):
let section = self.dependency.layoutProvider.createLayoutSection(module: module)
section.visibleItemsInvalidationHandler = { [weak self] _, _, _ in
guard let self else { return }
self.emitFetchLikedAction(module: module, sectionIndex: sectionIndex)
}
return section
case let .queryToggle(module):
return self.dependency.layoutProvider.createLayoutSection(module: module)
case .loadingIndicator:
return LayoutProvider.loadingIndicatorSection()
case let .space(module):
return self.dependency.layoutProvider.createLayoutSection(module: module)
case let .noResult(module):
return self.dependency.layoutProvider.createLayoutSection(module: module)
case let .buttonViewAll(module):
return self.dependency.layoutProvider.createLayoutSection(module: module)
case .footer:
return LayoutProvider.footerSection()
default:
return LayoutProvider.emptySection()
}
}
return layout
}
private func applyAppendSnapshot(with sections: [PlateViewSection]) {
var snapshot = self.dataSource.snapshot()
// loadingIndicator section delete
let sectionsToDelete = snapshot.sectionIdentifiers.filter { section in
section.module == .loadingIndicator
}
snapshot.deleteSections(sectionsToDelete)
snapshot.appendSections(sections)
sections.forEach { section in
snapshot.appendItems(section.items, toSection: section)
}
self.dataSource.apply(snapshot, animatingDifferences: false)
}
A ModelContainer with two configurations for two seperate models with one set to isStoredInMemoryOnly:false and the other one isStoredInMemoryOnly:true crashes after insertion. Anyone git this to work?
import SwiftData
@main
struct RecipeBookApp: App {
var container: ModelContainer
init() {
do {
let config1 = ModelConfiguration(for: Recipe.self)
let config2 = ModelConfiguration(for: Comment.self, isStoredInMemoryOnly: true)
container = try ModelContainer(for: Recipe.self, Comment.self, configurations: config1, config2)
} catch {
fatalError("Failed to configure SwiftData container.")
}
}
var body: some Scene {
WindowGroup {
ContentView()
.modelContainer(container)
}
}
}
struct ContentView: View {
@Environment(\.modelContext) private var context
@Query private var recipes: [Recipe]
@Query private var comments: [Comment]
var body: some View {
VStack {
Button("Insert") {
context.insert(Recipe(name:"Test"))
context.insert(Comment(name:"Test"))
}
List(recipes){ recipe in
Text(recipe.name)
}
List(comments){ comment in
Text(comment.name)
}
}
.padding()
.onAppear(){
context.insert(Recipe(name:"Test"))
context.insert(Comment(name:"Test"))
}
}
}
@Model
class Recipe {
internal init(name:String ) {
self.name = name
}
var id: UUID = UUID()
var name: String = ""
}
@Model
class Comment {
internal init(name:String ) {
self.name = name
}
var id: UUID = UUID()
var name: String = ""
}
Hello,
I am building a web app using Mapkit JS, and have something up an running where I can add markers and annotate places with Place ID (I followed along with the WWDC24 video).
However occasionally, while I'm doing nothing on the browser, I get an runtime error with the following error trace (from developer tools in Chrome).
===
Uncaught TypeError: Cannot read properties of null (reading 'tint')
at get tint (mapkit.core.annotations.d43c86.js:2:97102)
at get colorScheme (mapkit.core.annotations.d43c86.js:2:81602)
at e.exports.PlaceCardController._renderPlaceIframe (mapkit.core.map.536988.js:2:214785)
at e.exports.PlaceCardController.update (mapkit.core.map.536988.js:2:212978)
at e.exports.PlaceCardController._handleConfigChanged (mapkit.core.map.536988.js:2:213284)
at _handleConfigChangedListener (mapkit.core.map.536988.js:2:212679)
at n.dispatchEvent (mapkit.core.js:2:16624)
at mapkit.core.js:2:10799
===
It is completely random, and not a result of any browser / Map interaction.
Seems to be an issue in mapkit.core, and related to Place IDs.
Can anyone help with this?
Please...
Failed to build module 'Charts'; this SDK is not supported by the compiler (the SDK is built with 'Apple Swift version 6.0 effective-5.10 (swiftlang-6.0.0.7.41 clang-1600.0.24.1)', while this compiler is 'Apple Swift version 6.0 effective-5.10 (swiftlang-6.0.0.9.11 clang-1600.0.26.2)'). Please select a toolchain which matches the SDK.
ANY WORKAROUNDS?
I'm working on an iOS app that integrates with Spotify for authentication. I’m facing a problem where the app doesn’t handle URL schemes and app state transitions properly. Specifically, when Spotify redirects back to my app, it either doesn’t handle the URL correctly or doesn’t transition between states as expected. The authorization for spotify is successful, then my app reopens and nothing happens after that.
Expected Behavior: When Spotify redirects to my app, it should correctly handle the URL and process authentication parameters.
Actual Behavior: Even with URL handling code commented out, the app reopens from Spotify, which suggests a possible issue with how URL schemes or app state transitions are managed. The app’s state transitions don’t seem to be handled as expected.
Troubleshooting Steps Taken:
Verified URL schemes and redirect URIs.
Implemented application(_:open:options:) for URL handling.
Tested various app states (foreground, background, suspended).
//This code should open my app using the URL from spotify but this code never triggers and yet my app opens anyways//
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
print("Received URL: (url.absoluteString)")
handleSpotifyURL(url)
return true
}
private func handleSpotifyURL(_ url: URL) {
// URL handling logic
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Logic for when the app becomes active
}
//Using latest software for xcode, testing on iphone 14 with up to date software and up to date spotify
As mentioned - have ensure that my info plist is configured correctly, that spotify authorizes correctly, that the redirect URI is correct in my code and on spotify for developers.
From the testing I've done I imagine there is something wrong with how my app gets opened vs how it should get opened with the callback URL triggering func application(_ app: UIApplication, open url: URL, options:....
What I am expecting is that when spotify triggers the callback url - my app reopens with the above function and from there can retrieve the access token etc.
Hello everyone,
I really need your help here :-))
iOS App. 17 and up. Widget extensions and watchOS app as well.
New build for iOS 18 earlier this week.
All platforms works perfect, except the Apple Watch version, which crash constantly on launch. Testing on simulator and testing devices - works perfect. Uploading to TestFlight and running on the same device - crash.
The only thing I see in the crash report is StoredLocationBased.get error. It takes me to nowhere inside the project.
Opened a DTS to Apple as well. Any help here will be fully appreciated.
Thank you so much!
Hi,
The new TabBar, SideBar combination is very nice, but I tried customizing like text sizes, icon sizes using imageScale and all dint have any effect, also shows of selected item in side bar couldn't customize it, is there any suggestions ?
Kind Regards
I filed FB15170881 about this. When using .scrollPosition on a view that is inside a .navigationDestination, scrolling the ScrollView causes the content to jump around rather than animate smoothly. The same view placed outside of the .navigationDestination scrolls smoothly as expected.
To view this in action, use the example below. It's apparent on MacOS and iOS, as a Preview or run on-device.
Launch it
It will load to the problematic view by default.
Scroll the view in the square to see the janky movement.
You can also press the "back" button to go to a version of the same view that isn't nested inside a .navigationDestination. This one works smoothly as expected.
import SwiftUI
struct ContentView: View {
let items = [0, 1, 2, 3, 4]
@State private var position = ScrollPosition(idType: Int.self)
@State private var showPage: Bool = true
let height = 300.0
let width = 300.0
var body: some View {
NavigationStack {
VStack {
Text("This scrolls nicely.")
Text("It's at the navigation root.")
demoView
Spacer()
Button(action: {
showPage = true
}) {
Text("Go to broken version")
}
.buttonStyle(.bordered)
.navigationDestination(isPresented: $showPage) {
VStack {
Text("This stutters when scrolling.")
Text("It's in a navigationDestination.")
demoView
Spacer()
}
}
Spacer()
}
}
}
@ViewBuilder var demoView: some View {
let _ = Self._printChanges()
ScrollView(.vertical) {
LazyVStack(spacing: 0) {
ForEach(items, id: \.self) { _ in
Text("Scroll me")
.frame(width: width, height: height)
.border(.pink)
}
}
.scrollTargetLayout()
}
.frame(width: width, height: height)
.border(.blue)
.scrollPosition($position)
}
}
#Preview {
ContentView()
.modelContainer(for: Item.self, inMemory: true)
}
I used tabBarItem & UITabBarController create a demo app.
then I set every pages backgroudcolor as red.
when I change to every pages withing the tabBarItem at bottom. the page's background color highlight every time.
I don't know why. Is this the new UIKit's bug?
Watch OS11 My recording play gets paused when watch I turned down.
It was not happening in previous versions.
In my app I recorded my recording.
And When I play it in my app,
it was playing good in debug mode(when Xcode is connected) could not debug.
Otherwise, it was automatically paused(when my wrist is down or inactivity time is elapsed)
I want it to be continued.