I have a ScrollView which has inside a LazyVStack and multiple rows. On the appearing of the ScrollView, I scroll to row 250.
When having the VoiceOver running, after opening the app, the focus is on the navigation title as it should be, than, after swiping right to enter the ScrollView, one would expect the focus to be placed on the first visible row, but this is not the case, it scrolls back to some row and focus on that, than reads it.
Here is the code to reproduce it, and if you ask me, this is pretty standard stuff I don't do anything special.
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
ScrollViewReader { scrollProxy in
ScrollView {
LazyVStack {
ForEach(1...500, id: \.self) { index in
NavigationLink(destination: DetailView(row: index)) {
Text("Row \(index)")
.padding()
.frame(maxWidth: .infinity)
.background(Color.gray.opacity(0.2))
.cornerRadius(8)
.padding(.horizontal)
}
}
}
}
.onAppear {
// Scroll to row 250 when the view appears
withAnimation {
scrollProxy.scrollTo(250, anchor: .center)
}
}
}
.navigationTitle("Rows")
}
}
}
struct DetailView: View {
let row: Int
var body: some View {
VStack {
Text("Detail for Row \(row)")
.font(.largeTitle)
.padding()
Spacer()
}
.navigationTitle("Row \(row) Details")
}
}
@main
struct ScrollViewExampleApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
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
crash log
Anyone can understand the log? I really don't understand.
Please see the attachment crash and help to resolve it, thanks very much.
Hello everyone, I am using the new AccessorySetupKit, and whenever I try to remove an accessory I sometimes get an alert asking me to make sure if I want to remove the accessory from my device. The problem is that this alert sometimes shows up, and sometimes it does not. The removal of the accessory does work, it is just that the alert is not predictable. Is this expected behavior? How can we “predict” when it will show up and when it will not?
I use the effect in the picture to do the test, I want to achieve a habit of multiple punch card effect, click to complete a punch card, long press to cancel a punch card.
I'm having a problem right now. I want the long press gesture to only work on the trash icon, not extend to the entire item, causing the entire item to be highlighted.
What should I do about it? I tried a lot of methods, but I didn't achieve the effect.
I need to add an accessory view with a text field to an NSAlert. This works as expected but as my app comes in different languages, the alert looks a bit different depending on the language used:
So I wonder how I can make the text field automatically use the full width of the alert window. I tried to call the alert's layout method and then resize the text field but this seems not work in all cases. Any help would be highly appreciated. Thanks!
Dear all, how do I add any extra buttons to the AVPlayer / VideoPlayer menu? I would like to add a button e.g. linking to a particular website.
Thank you!
I would like to program an app in Swift Playground that displays WhatsApp Web in a webview, so to speak. But I keep seeing an error like in the screenshot.
My Code:
import SwiftUI
import WebKit
import PlaygroundSupport
struct WebView: UIViewRepresentable {
let url: URL
func makeUIView(context: Context) -> WKWebView {
let webView = WKWebView()
let request = URLRequest(url: url)
webView.load(request)
return webView
}
func updateUIView(_ webView: WKWebView, context: Context) {
}
}
struct ContentView: View {
var body: some View {
WebView(url: URL(string: "https://web.whatsapp.com")!)
.edgesIgnoringSafeArea(.all)
}
}
PlaygroundPage.current.setLiveView(ContentView())
I have added an custom attribute for a paragraph using the below method
textStorage.addAttribute(.customCase, value: "checkList", range: paragraphRange)
When I insert some text in between the text which contains the custom attribute, that text is not inheriting/propagating the custom attribute of existing paragraph text
Old Text : - This is a test
New Text : - This is "some new" a test
The inserted part is not getting the custom attribute of the old text, Can I know why it's happening, Is it some textKit2's behaviour.
Hello, my app uses vibrancy effects thanks to SwiftUI's materials and hierarchical shape style. While they work flawlessly on iOS and iPadOS, on Mac Catalyst they seem to be pretty broken.
I'm attaching some screenshots.
iPad
Mac
This is the same code, with the same background behind the material. The colors are already pretty different, but my concern is about the text, which clearly looks broken
Here a sample code:
HStack(spacing: 0) {
VStack(alignment: .leading, spacing: 2) {
Text(event.label)
.font(.subheadline.weight(.semibold))
.foregroundStyle(.secondary)
Text(event.info(for: currentDestination))
.font(.system(.title2, design: .rounded, weight: .semibold))
.foregroundStyle(.primary)
}
Spacer(minLength: 0)
InfoIcon(isCustom: event.isCustomIcon, icon: event.icon, renderingMode: .palette, size: iconSize)
.font(.body.weight(.semibold))
}
.padding(.horizontal, 24)
.padding(.vertical, 12)
.background(.quaternary, in: .rect(cornerRadius: 16, style: .continuous))
.clipShape(.rect(cornerRadius: 16, style: .continuous))
.padding(.all, 16)
.background(.ultraThinMaterial, in: .rect)
On MacOS when TabView is in sidebarAdaptable mode:
Clicking the Tab directly on the text of its label, or its systemImage, does not actually select the Tab.
The only way to select the Tab is to click whitespace around the text, for example to the right side of the text. iOS has behavior better – you can click the text or image to select the Tab.
This behavior is really bizarre and not user-friendly. I'm surprised it could even ship like this. Tabs are actually unusable in sidebarAdaptable because users should not have to be explained to that they need to click on whitespace.
Am I missing something? Seems almost too strange to be a bug.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Hello. I am here to report a problem.
I was investigating the strange behaviour of my text animation, and I've found out that unrelated TimelineView is causing the problem.
text is animating on change and there are colors on background (in ZStack) that change using TimelineView.
As a result, when the text changes, it twitches, until it fills the whole screen width. If I pause TimelineView animation, everything works smoothly
The problem occurs only on a real device. I've tested on iOS 17 and 18
Example code
struct ContentView: View {
@State var open = false
let colors: [Color] = [.cyan, .red, .green, .gray, .blue, .orange, .pink, .purple]
@State var i: Int = 0
@State
var text: String = chunks[0]
@State var pause = false
var body: some View {
ZStack {
TimelineView(.animation(minimumInterval: 1.2, paused: pause)) { context in
let color = colors[Int(context.date.timeIntervalSinceReferenceDate) % colors.count]
ZStack {
color
.animation(.easeInOut(duration: 1.2))
Rectangle().fill(Material.regular).edgesIgnoringSafeArea(.all)
}
}
VStack {
Spacer()
Text(text)
.font(.system(size: 32))
.multilineTextAlignment(.center)
.padding()
.animation(.linear(duration: 0.1), value: text)
Spacer()
Button("Add text") {
if i < (chunks.count - 1) {
i += 1
} else {
i = 0
text = ""
}
text.append(" " + chunks[i])
}
Button("Toggle background animation") {
pause.toggle()
}
}
}
}
}
let lyrics = "I'm born to run down rocky cliffs Give me grace, bury my sins Shattered glass and black holes Can't hold me back from where I need to go"
let chunks = lyrics.components(separatedBy: " ")
I have encountered a tricky problem and hope to receive help.
My APP process does not exist, and then I click on the notification message of the APP to open it. At this time, my APP will first configure uitabbarccontroller, and then push the first (index=0) viewcontroller (A) from the tab to the notification message list viewcontroller (B). However, I found that on iOS18, the lifecycle of A (viewDidLoad) did not execute at the end of this process.
I am sure this problem will occur stably on iOS18.1.1.
Versions lower than iOS18 will not.
Can someone tell me why this is?
My picker looks like this:
Picker("Color", selection: $backgroundColor.animation(), content: {
ForEach(TransactionCategory.Colors.allCases, id: \.self) { color in
Text(color.rawValue)
.tag(color)
.foregroundStyle(color.getColor())
}
})
This changes a tint color which is applied to the entire tabview. I can see that it's working because the buttons in the top tab bar are changing color as I change the picker value. However, the color of the text inside the picker is not changing until I go back one view and then come back to this view. I tried setting an ID on the picker and then updating it when the picker value changes, but that didn't work.
Any ideas?
Wrapping views with a VStack breaks animation, but using an extension to do the same thing fixes it.
I was having issues with views transitioning between being visible and not visible inside of List. They would appear, but the animation would be jerky. I switched to using a Section, and the animation looked much better. However, the spacing between views and padding wasn't what I wanted. So I wrapped some of the views inside the Section with a VStack.
But first, this is how my view SectionView looks:
struct SectionView<Content: View>: View {
let title: String
@ViewBuilder var content: () -> Content
var body: some View {
Section {
Text(title)
.font(.title3.bold())
content()
}
.listRowInsets(EdgeInsets(top: 10, leading: 20, bottom: 10, trailing: 20))
.listRowBackground(Color.clear)
.listRowSeparator(.hidden)
.contentShape(.rect)
}
}
Below was in a separate view:
SectionView(title: "Title") {
Group {
HStack {
// Stuff here
}
if let selectedMonth {
VStack(alignment: .leading, spacing: 10) {
// Stuff here
}
}
}
.animation(.smooth, value: selectedMonth)
}
This, however, broke the animations again when the VStack appears. It went back to being jerky. So instead of wrapping the content inside of a VStack, I created an extension to do the same thing.
extension View {
@ViewBuilder
func condensed() -> some View {
VStack(alignment: .leading, spacing: 10, content: {
self
})
}
}
So now instead of wrapping it in a VStack, I do this:
if let selectedMonth {
Group {
// Stuff here
}
.condensed()
}
The animations look good again. I just can't figure out why that is. Can anyone help me understand this?
I am working with Selenium but after upgrading to Sequoia 1.0.1, my testing tool is not Lon get working for safari.
I checked following file exits:
/usr/bin/safaridriver
and it is no there
Topic:
UI Frameworks
SubTopic:
General
Noticed in iOS 18 that List element with animation modifier behaves differently. Seems that on first change of the underlying State property List updates all elements and loses its scroll position even if you insert just one element.
The following code reproduces the behaviour, if you run it on iOS 17 it will behave as expected, you'll see an element being added to the list with an acompanying animation. On iOS 18 you'll lose your scroll position and judging by the animation it seems to update all the other rows in the list even though only one element of the underlaying State property was inserted. After that first update, list element on iOS will behave as expected.
To reproduce the issue scroll down to the ~50th element and tap on a row, compare the behaviour on iOS 17 and iOS 18.
import SwiftUI
struct ContentView: View {
struct ViewState: Equatable {
struct Value: Identifiable, Equatable {
let id: String
var text: String
var value: Bool
}
let list: [Value]
}
@State var viewState: [ViewState.Value] = {
return (0..<100).map { id in
ViewState.Value(
id: "\(id)",
text: "Row number: \(id + 1)",
value: Bool.random()
)
}}()
var body: some View {
list(viewState)
}
@ViewBuilder
private func list(_ list: [ViewState.Value]) -> some View {
List {
ForEach(list) { row in
self.value(row)
}
}
.animation(.default, value: viewState)
}
@ViewBuilder
private func value(_ value: ViewState.Value) -> some View {
Button(action: {
guard let rowIndex = viewState.firstIndex(where: { $0.id == value.id }) else {
return
}
viewState.insert(randomValue(id: rowIndex), at: rowIndex + 1)
}) {
VStack {
Text(value.text)
Text("\(value.value ? "ON" : "OFF")")
.foregroundStyle(value.value ? Color.green : Color.red)
}
}
}
private func randomValue(id: Int) -> ContentView.ViewState.Value {
let id = (id*100 + 1)
return .init(id: "New id: \(id)", text: "Row number: \(id)", value: Bool.random())
}
}
Issues has already been reported using feedback assistant FB16082730
I'm working on an app that will be used in laboratory conditions. The application must be as dim as possible. For all the text and buttons, I'm thus using Color(red: 0.1, green: 0.0, blue: 0.0).
However, a bright Home Bar / Swipe up bar emerges whenever the user interacts with the screen. This characteristic renders the iPhone useless in those conditions. In the Android version, such problems do not exist.
And, I have yet to find a solution here in this forum or elsewhere. I must force the Home Bar to be invisible or Color(red: 0.1, green: 0.0, blue: 0.0). How to do that? Can anybody help?
Topic:
UI Frameworks
SubTopic:
SwiftUI
In MacOS app I present modally NSTableView.
The table is created in IB and its data and functionality are handled in corresponding NSViewController.
As long as the positioning of modally presented table is left to the system, the tableview is placed in the center of the presenting view controller and everything works fine.
But if I apply NSLayoutConstraints to position it as I need for visual design reasons, the table stops responding to mouse clicks.
Here's the code inside the presenting view controller:
bookmarks_TVC = Bookmarks_TVC()
bookmarks_TVC.view.translatesAutoresizingMaskIntoConstraints = false
self.present(bookmarks_TVC, animator: ModalPresentationAnimator())
NSLayoutConstraint.activate([
self.bookmarks_TVC.view.leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant:410),
self.bookmarks_TVC.view.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 170)
])
Once again, without NSLayoutConstraints the table responds as expected. Once the constraints are added, it becomes unresponsive.
Thanks in advance for any helpful suggestions.
Topic:
UI Frameworks
SubTopic:
AppKit
When working with SwiftUI TabView and ScrollView at root level with scrollPosition(id:anchor:), after tapping on Tab item the ScrollView scrolls to the top, but the scroll position ID does not get updated.
struct ContentView: View {
@State var positionID: Int?
var body: some View {
TabView {
Tab("Test", systemImage: "house") {
ScrollView(.vertical) {
LazyVStack(pinnedViews: [.sectionHeaders]) {
ForEach(0 ... 100, id: \.self) { index in
Text("\(index)")
}
}
.scrollTargetLayout()
}
.scrollPosition(id: $positionID, anchor: .top)
.onChange(of: positionID) { _, newValue in
print(newValue)
}
}
}
}
}
FB15964820
To store the data, I used the following api:
(nullable UIPasteboard *)pasteboardWithName:(UIPasteboardName)pasteboardName create:(BOOL)create
The official document says that starting from iOS10, clipboard data does not support persistence, but from the test practice, I use this clipboard to save the data always exists, no matter uninstall and reinstall the APP, restart the phone, or even update the system, then what scenarios may lead to the clipboard data is deleted, using this scheme to store data is reliable?