I have tried a lot of codes to see what’s the difference between browser and editor, but I can’t find some changes between those two things, so i’m wondering what’s the difference between browser and editor?
Post
Replies
Boosts
Views
Activity
How to add a custom button to the Edit Menu on both iOS and iPadOS natively using SwiftUI.
I have seen many ways to implement custom button using UIKit but wondering how to use SwiftUI to achieve the same thing.
I have never seen any modifiers or Menus about this. I guest there is no way to do that.
Any idea about this? or is it a future update for SwiftUI ??
I am working on an app that allow user to taking notes, and I want to support inline editing that means users can use PencilKit feature and edit text in a single note just like the Notes app.
Is there any good idea to achieve this using SwiftUI?
I have done the same thing in SwiftUI using UIViewRepresentable, but toolPicker doesn't show so I checked isFirstResponder property and I found that it was still false after I called canvas.becomeFirstResponder().
Check this out:
struct NoteCanvasView: UIViewRepresentable {
func makeUIView(context: Context) -> PKCanvasView {
let canvas = PKCanvasView()
canvas.drawingPolicy = .anyInput
canvas.delegate = context.coordinator.self
let toolPicker = PKToolPicker()
toolPicker.setVisible(true, forFirstResponder: canvas)
toolPicker.addObserver(canvas)
print(canvas.canBecomeFirstResponder)
canvas.becomeFirstResponder()
print(canvas.isFirstResponder)
return canvas
}
func updateUIView(_ canvas: PKCanvasView, context: Context) {
canvas.becomeFirstResponder()
}
func makeCoordinator() -> Coordinator {
Coordinator(self)
}
class Coordinator: NSObject {
var parent: NoteCanvasView
init(_ parent: NoteCanvasView) {
self.parent = parent
}
}
}
I found canvas.canBecomeFirstResponder returns true and canvas.isFirstResponder always returns false.
Is this a bug in current version of SwiftUI??
I am working on a SwiftUI project and in a subview I use @FetchRequest to fetch data from CoreData. I have a menu to let user select which data to fetch, and by default I want to fetch all datas.
The problem is when user open the menu and select a category then it refetch the data, it's correct and when user close the menu, the nsPredicate that the user have given will disappear and switch to the default predicate.
I tried to write the same pattern code on 'EarthQuake' sample app, it has the same problem.
And here is the code:
List(selection: $selection) {
ListView(search: $searchText)
}
.background(toggle ? Color.red.opacity(0.01) : nil)
.toolbar {
ToolbarItem(placement: .bottomBar) {
Button {
toggle.toggle()
} label: {
Text("Toggle")
}
}
}
.searchable(text: $searchText)
ListView:
struct ListView: View {
@FetchRequest(sortDescriptors: [SortDescriptor(\.time, order: .reverse)]) // predicate: nil
private var quakes: FetchedResults<Quake>
@Binding var search: String
var body: some View {
ForEach(quakes, id: \.code) { quake in
NavigationLink(destination: QuakeDetail(quake: quake)) {
QuakeRow(quake: quake)
}
}
.onChange(of: search) { newValue in
quakes.nsPredicate = newValue.isEmpty ? nil : NSPredicate(format: "place CONTAINS %@", newValue)
}
}
}
I can filter data by typing in the search field but when I click on Toggle Button, it may refresh the ParentView which cause the @fetchRequest to update and nsPredicate return to nil.
Is this a bug? Or maybe my understand was wrong. And is there any good suggestions?
In the past, I use UIApplication.shared.windows.first?.safeAreaInsets.bottom to get the bottom safe area, but in iOS 15, there is an warning shows that windows has been deprecated.
My project is written in SwiftUI, so is there a way to get the global safeAreaInsets again and fits iOS 15?
In the session, I have seen a lot of examples of rainbow effects and I'd like to bring it into my app written by SwiftUI, but one thing missing is that I'm not sure how to implement customizable markdown analysis and how to set the style for it. Please help me, maybe give me some ideas? or just some suggestions.
Could you please provide a option for developers to convert drawing shape to ideal shape?
Something like this:
canvas.convertIdealShape = true
(default by false)
I use lazyVStack lazyGrid and ScrollView to build a Symbol Picker. But you know, there are more than 1300 symbols in Symbol Library. So I use LazyVStack and LazyVGrid.
Here is my code:
ScrollView {
LazyVStack {
VStack(alignment: .leading) {
CategoryNameIndicator()
LazyVGrid(columns: columns) {
ForEach(symbolGroup.symbolsName, id: \.self) { symbol in
SymbolPickerCell(symbol: symbol,
canBeSelected: true,
selectedSymbol: $symbolLibrary.selectedSymbol)
.padding(15)
.padding(.bottom, 5)
}
}
.compositingGroup() // -> I don't know if this will improve the performance. But I used.
}
}
}
My problem is: When I scroll very fast. CPU usage will goes to 100% and the performance is reeeally bad. Scrolling Animation is caton. Do you have any suggestions?