I am getting following warning in the console when presenting SwiftUI's ShareLink:
[LayoutConstraints] Changing the translatesAutoresizingMaskIntoConstraints property of a UICollectionReusableView that is managed by a UICollectionView is not supported, and will result in incorrect self-sizing. View: <_UIActivityContentFooterView: 0x12f7a82d0; baseClass = UICollectionReusableView; frame = (16 241; 343 52); layer = <CALayer: 0x600002409c80>>
I am curious if this is my wrong configuration / presentation of SwiftUI's ShareLink in SwiftUI app or this is a problem within SwiftUI wrapper around UIActivityViewController
.toolbar(content: {
ShareLink(item: Image(uiImage: fileImage),preview: SharePreview(displayName, image: Image(uiImage: fileImage)))
})
Question relates to iOS 16.2
Related
I have a UIViewRepresentable that represents a PKCanvasView.
struct PKCanvasRepresentable : UIViewRepresentable
{
#Binding var canvas: PKCanvasView
func makeUIView(context: Context) -> PKCanvasView {
canvas.tool = PKInkingTool(.pen, color: .black, width: 2)
canvas.drawingPolicy = .anyInput
canvas.isOpaque = false
canvas.backgroundColor = .clear
return canvas
}
func updateUIView(_ uiView: PKCanvasView, context: Context) {}
}
I want to use it as part of a sheet, that contains other input components and must be vertically scrollable.
#State var canvas = PKCanvasView()
var body: some View {
NavigationView {
ScrollView {
VStack {
// ..various components..
PKCanvasRepresentable(canvas: $canvas)
}
}
}
}
The drawing does not work, because the drawing gesture gets canceled by the scroll gesture.
I would like the PKCanvasView related gestures having priority over the scroll view ones. How can i achieve this?
Example
The expected behaviour can be seen when - for example - a DatePicker in wheel style is in a ScrollView. The scroll view does not receive any gesture input when interacting with the DatePicker. I would like to have the same behaviour for a PKCanvasView.
Additional info
I tried to add various Gesture modifiers to the Representable which prevents the ScrollView from getting input events - but of course that also prevents the Canvas from getting user input.
I built a drawing component myself in the past which worked, because i had control over the Gestures that were added to make the component happen. But i would prefer to use PKCanvasView, which does everything i need already - except from the described issue.
I saw this question - but it has nothing to do with PKCanvasView and its solution does not help.
I tried ai based code generators - but i don't have any subscriptions so i'm limited in tries and length of the answer. I tried the following quote, which produced only invalid, tutorial level answers:
Write a SwitUI view that contains of a ScrollView which has a nested UIViewRepresentable of a PKCanvasView where the ScrollView does not receive any kind of user input, events or gestures while the user interacts with the PKCanvasView and tries to draw but functions normally whenever the user does not interact with the PKCanvasView
SwiftUI View Hierarchy
Navigation View --> VStack --> Custom SearchView --> TabView
In the view, with the hierarchy mentioned above, I'm unable to remove navigation bar. It's visibility is successfully changed with the code mentioned shared below.
#available(iOS 15.0, *)
func iOS15UIBarSpecs(){
let navBarAppearance = UINavigationBarAppearance()
navBarAppearance.configureWithTransparentBackground()
navBarAppearance.backgroundColor = UIColor.red.withAlphaComponent(0.5)
navBarAppearance.shadowImage = UIImage()
navBarAppearance.shadowImage = nil
navBarAppearance.shadowColor = nil
UINavigationBar.appearance().standardAppearance = navBarAppearance
UINavigationBar.appearance().scrollEdgeAppearance = navBarAppearance
}
The presence of this navigation bar is blocking tap gestures on any view coming behind it.
The same view was working fine in iOS 14 with the following line of code.
.navigationBarHidden(true)
Any help would be much appreciated. Thanks!
I updated my SwiftUI Watch App from Xcode 11 to Xcode 12, using the new Xcode 12 / SwiftUI LifeCycle methodology. Unfortunately in doing that the "tint color" (which defines the color of NavigationBar back button & test) is lost & reverts to the defaults (which is not what I want or had set before in Xcode 11).
Does anyone know how to change the color of the ‘back’ button & text on NavigationBar - using the new lifecycle SwiftUI with Xcode 12 & WatchOS7?
In xcode 11 one could change the ‘tint’ color using inspector on the StoryBoard to do that (for the whole App). But with the new SwiftUI lifecycle in xcode 12, I can’t figure out how this is now set (probably some parameter in ‘init()’ of App?)
I have tried the the below code but it gives the below syntax error (remember this is for WatchOS7):
"Cannot find 'UINavigationBarAppearance' in scope"
#main
struct myApp: App {
init() {
print("App Initializing....")
let navBarAppearance = UINavigationBarAppearance()
navBarAppearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white]
navBarAppearance.titleTextAttributes = [.foregroundColor: UIColor.white]
}
#SceneBuilder var body: some Scene {
WindowGroup {
ContentView()
}
}
}
Also tried:
#SceneBuilder var body: some Scene {
WindowGroup {
ContentView().accentColor(.white)
}
But that has no effect (no matter where the .accentColor modifier is placed).
Any help / suggestions?
Thanks!
Gerard
SwiftUI NavigationBar WatchOS7
OK - figured it out from Apple Documentation!
See: https://developer.apple.com/documentation/watchos-apps/setting-the-app-s-accent-color/
and follow instructions for "Update Existing Projects"
NOTE:
The new "AccentColor" color set must be added to the assets in the Frameworks->AppName WatchKit App->Assets.xcassets file. This is the same file where the App's Icon is placed.
One of the new features of SwiftUI 2 are LazyVStacks. Is it possible to implement its functionality in the current SwiftUI framework? I have the following code sample where I want to use it:
var body : some View {
VStack(alignment: .leading){
ScrollView {
Text("sample")
VStack{ // I want to have a LazyVStack here
ForEach(1..<10000, id: \.self) {_ in
Text("test")
}
}
}
}
}
Normally i would use a List which is by default lazy. But due to other constraints it's not possible.
Thanks in advance.
You have to install Xcode 12 beta in order to use LazyStacks. If you are coding for an iOS app, the simulator will run correctly, but if you are coding for a macOS app you will have to update to Big Sur also in order to run the SwiftUI 2 code.
The PresentationButton presents the view properly, but upon hitting "Cancel" to return to parent view, the button refuses to present the child view again.
Here is my PresentationButton code:
struct ContentView : View {
var body: some View {
ZStack {
PresentationButton(Text("Click to show"), destination: SomeOtherView())
.transition(.slide)
}
}
}
This bug has existed in various forms until Xcode 11 beta 4, but note that the API has changed.
PresentationButton became PresentationLink and then was deprecated in Xcode 11 beta 4 in favor of .sheet.
See here for an example of how to use the new functionality: https://stackoverflow.com/a/57087399/3179416