Post

Replies

Boosts

Views

Activity

Reply to .trim() Shape SwiftUI
I want to trim it 50% but from top to bottom, so I want it trimmed from the center to the top. Thanks for your reply. In fact, I expected some more info about all the views in your app, if there is any other views overlapping to your shape or how your shape is arranged in your app, etc... Sorry, my words are not enough. So, assuming the simplest case, you may use clipShape. Define your clipping rect, for example: struct RectBand: Shape { var from: CGFloat var to: CGFloat func path(in rect: CGRect) - Path { Path { path in path.addRect(CGRect( x: rect.origin.x, y: rect.origin.y + from * rect.size.height, width: rect.size.width, height: (to-from) * rect.size.height )) } } } And use it with clipShape like this: Raindrop() .clipShape(RectBand(from: 0.4, to: 0.9)) .scaledToFit() Of course you may need to adjust the values from and to.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to .trim() Shape SwiftUI
it trims from right to left, It is not the right description of trim(from:to:). It trims from the start of the path to the end of the path. With your Raindrop, this code: Raindrop() .trim(from: 0.4, to: 0.6) .scaledToFit() would show you the lower portion of the path. If you want to cut arbitrary shape with some band from top to bottom, you may need something other than trim(from:to:).
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to How do I hide a button using Swift5 when an 'if' condition is true?
a button called "itemOneDelete" I guess you have two different kinds of itemOneDelete, a button and the method itemOneDelete(_:). And Xcode is assuming itemOneDelete as the method, not the button. Generally, Xcode can distinguish the two things if you declare them properly. Do you have the IBOutlet declaration of the button itemOneDelete? @IBOutlet weak var itemOneDelete: UIButton! Or else, there may be something wrong in the other parts of your code. Can you show whole code of your view controller? By the way, your question has nothing to do with the SwiftUI framework. The tag SwiftUI is not appropriate for your question.
Topic: UI Frameworks SubTopic: UIKit Tags:
Apr ’21
Reply to Problem With Filter
Okay I will look at my code again, I will recopy it. Thanks. I have copied all the code you have shown in this thread, modified some methods as I have shown. (And I needed to fill many parts to make the project build and run.) And then replaced some parts to provide some test data and I could not reproduce the issue you have described: there are issues with selectedScope 0, When I filter for a specific player in selectedScope 0, I see multiple cells of the same player instead of one. When I delete all character it should clear and reload one of those fetch methods instead of giving multiple cells of the same player. After I delete all characters and when I try to start typing again in the searchBar I see no cells shown. If you could show some info why all those things were happening, I would try to solve the issue, but currently I have no clue what's going on.
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to MTLTexture -> CIImage -> CGImage crash on options not nil
What am I missing? Have you tried changing line 4 as follows? let options: [CIImageOption: Any] = [CIImageOption.colorSpace: CGColorSpace(name: CGColorSpace.linearSRGB)!] The doc of CIImageOption.colorSpace - https://developer.apple.com/documentation/coreimage/ciimageoption/1438131-colorspace says: The value you supply for this dictionary key must be a CGColorSpace data type. As you know CGColorSpace.linearSRGB is CFString, not CGColorSpace. There may be other parts affecting this behavior, so you may have other places to fix. But the value of options seems to be one thing you need to fix.
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21
Reply to Simplify code with textfield and textview delegate methods?
This is what I do in some of my apps. Put all the textFields and textViews into a UIStackView, and add a proper constraint at the bottom. @IBOutlet weak var bottomConstraint: NSLayoutConstraint! override func viewDidLoad() { super.viewDidLoad() //... NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(_:)), name: UIResponder.keyboardWillHideNotification, object: nil) } @objc func keyboardWillShow(_ notification: Notification) { print(notification) if let keyboardBounds = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue { bottomConstraint.constant = -keyboardBounds.height } } @objc func keyboardWillHide(_ notification: Notification) { if let _ = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue { bottomConstraint.constant = 0 } } It is a bit difficult to add a proper constraint to the bottom of a UIStackView if you are not accustomed to it, but once done, changing bottomConstraint would move up all the fields and they will not be hidden.
Topic: UI Frameworks SubTopic: UIKit Tags:
Apr ’21
Reply to Changing UITabBar item image on selected and unselected state for Three Tabs but getting error
You can modify the properties of each UITabBarItem: if let tabBarItem1 = self.tabBarController?.tabBar.items?[0] { tabBarItem1.title = "Myanmar" tabBarItem1.image = UIImage(systemName: "m.square.fill") tabBarItem1.selectedImage = UIImage(systemName: "m.square") } if let tabBarItem2 = self.tabBarController?.tabBar.items?[1] { tabBarItem2.title = "Singapore" tabBarItem2.image = UIImage(systemName: "s.square.fill") tabBarItem2.selectedImage = UIImage(systemName: "s.square") } if let tabBarItem3 = self.tabBarController?.tabBar.items?[2] { tabBarItem3.title = "Hyderabad" tabBarItem3.image = UIImage(systemName: "h.square.fill") tabBarItem3.selectedImage = UIImage(systemName: "h.square") }
Topic: UI Frameworks SubTopic: UIKit Tags:
Apr ’21
Reply to SwiftUI passing Core Data between Views Error
Can you try something like this? struct ListView: View { @Environment(\.managedObjectContext) var viewContext @FetchRequest(sortDescriptors: []) var items: FetchedResultsItem @State var showEditItemSheet = false @State var itemToEdit: Item? var body: some View { List { ForEach(items) { item in ListItemView(item: item) .onTapGesture { itemToEdit = item showEditItemSheet.toggle() } } } .sheet(isPresented: $showEditItemSheet) { ListViewSheetContent(item: $itemToEdit, showEditItemSheet: $showEditItemSheet) } } } struct ListViewSheetContent: View { @Binding var item: Item? @Binding var showEditItemSheet: Bool var body: some View { EditItemView(item: item!, showEditItemSheet: $showEditItemSheet) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to SwiftUI Rerun animation when property changes.
How about something like this? struct ContentView: View { @State private var status: String = "" var body: some View { VStack(spacing: 0) { Spacer() BackgroundView(status: $status) Spacer() Button(action: { if status == "1" { status = "2" } else if status == "2" { status = "3" } else { status = "1" } }, label: { Text("next status") }) Spacer() } .onAppear { status = "1" } } } struct BackgroundView: View { @Binding var status: String @State var isAnimating: Bool = false var body: some View { ZStack { Group { Image(systemName: "\(status).circle.fill") .resizable() .scaledToFit() .frame(width: 220) .foregroundColor(.red) } .scaleEffect(isAnimating ? 1.0 : 0, anchor: .top) } .onChange(of: status) {_ in isAnimating = false withAnimation(Animation.easeOut(duration: 0.4)) { isAnimating = true } } } } Your BackgroundView will animate as expected when isAnimating changes from false to true. So, do it onChange of status.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to Run something before another thing
The completion handler isn't being called. Ideas? That would never happen. This thread is too old and too long, many readers would not visit old and long thread. Better start a new thread and show the complete code which can reproduce the issue you are facing.
Topic: UI Frameworks SubTopic: UIKit Tags:
Apr ’21