Post

Replies

Boosts

Views

Activity

How to explain the behavior of ".frame" when placed after ".offset"
According to the documentation of ".offset", The original dimensions of the view aren’t changed by offsetting the contents; in the example below the green border drawn by this view surrounds the original position of the text: Text("Hello, World!")             .border(Color.black)             .offset(x: 10.0, y: 50)             .border(Color.green) IMO, the modifer (ie,.border(Color.green))followed ".offset" should only affect the original view, but not the new view. When add a ".frame" right after the ".offset", I thought it also only affect the original view. However, the original and the new view are both affected. Text("Hello, World!")             .border(Color.black)             .offset(x: 10.0, y: 50)   		.frame(width:50)             .border(Color.green) Further more, if I keep adding another ".frame" right after the first one, only the original view is affected again. Text("Hello, World!")             .border(Color.black)             .offset(x: 10.0, y: 50)             .frame(width:50)             .frame(width:100)             .border(Color.green) What happened under the hood? Thanks in advanced.
0
0
302
Feb ’21
live preview problem
I want to test the code below in live preview, but it seems not to work. In simulator, the button can change the text well, but not in live preview. How to fix it? Thanks in advance. import SwiftUI struct PreviewOnchangeTest: View {     @Binding var toggle: Bool     @State var text = "nice"     var body: some View {         VStack{         Text("\(text)")             .onChange(of: toggle, perform: { value in                 text = toggle.description             })         Button(action: {toggle.toggle()}, label: {             Text("change")         	})         }     } } struct PreviewOnchangeTest_Previews: PreviewProvider {     @State static var toggle = true     static var previews: some View {         PreviewOnchangeTest(toggle: $toggle)     } }
1
0
1.1k
Jan ’21
can't open documentation __update problem
I update my Xcode to the latest version today. After that, I can't access the developer documentation from the Xcode anymore. The error report says: Application Specific Information: Sending windowMenu_showDocumentation: to IDEDocCommandHandler from <NSMenuItem: 0x7f99fa73ee00 Developer Documentation> ProductBuildVersion: 12A7209 ASSERTION FAILURE in /Library/Caches/com.apple.xbs/Sources/IDEPlugins/IDEPlugins-17192/IDEDocViewer/DocumentationNavigator.swift:142 How can i solve the problem? Thanks in advance.
3
0
554
Sep ’20
“escape-sequence” in documentation
In the swift official documentation: "the swift programming language"-"LANGUAGE REFERENCE"-"Lexical Structure"-"String Literals"-"GRAMMAR OF A STRING LITERAL". It says: escape-sequence → \ extended-string-literal-delimiter and "extended-string-literal-delimiter → extended-string-literal-delimiter opt" I think: escape-sequence SHOULD → \  NOT → \ extended-string-literal-delimiter Am I right? Thanks in advance.
2
0
515
Aug ’20
A weird question to display image on simulator
I encounter a problem. I create a UIImageView to display a large image(16,000*3,200pixels). It could display on the device quite normally. However, it couldn't display on the simulator, totally blank. If i change to a little smaller image(1532*513pixels). It could display normally both on simulator and device.
1
0
768
Mar ’20
how to interpret "scale"
In the Developer Documentation "UIKit-touches presses gestures-UIPinchGestureRecognizier-var: scale". In the section of Discussion, it said"You may set the scale factor, but doing so resets the velocity......Apply the scale value to the state of the view when the gesture is first recognized—do not concatenate the value each time the handler is called." What does it exactly mean?Something about "incremental" "exponential"?
8
0
804
Mar ’20
Will cs193p Stanford University class update?
I'm learning the Stanford University class called: “cs193p 2017" Developing apps for ios 11. It is quite excellent. And I really learned a lot. I'm trying to search the Stanford University class named Developing apps for ios 12 or 13 by Paul Hegarty. But I failed. Does anyone know wheather the series lecture will update? Or any excellent video about developing apps for ios13 to be recommended? Thanks in advance.
4
0
4.2k
Mar ’20
How to explain completionHandler(true) or (false)
I am following a tutorial online regarding a TableView Cell swipe action.override func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -&gt; UISwipeActionsConfiguration? { let like = UIContextualAction(style: .normal, title: "Like") { (_, _, isComplete) in self.favStatusCollection[indexPath.row] = !self.favStatusCollection[indexPath.row]// Call completion handler to dismiss the action button isComplete(true) }However, if I call isComplete(false) instead of isComplete(true). It makes no difference in action in the running test.
7
0
2.6k
Feb ’20
how to call the function in class
struct Weather{ var city :String? var temp :String? var weather :String?}class ViewController: UIViewController { @IBOutlet weak var labelWeather: UILabel! @IBOutlet weak var labelCity: UILabel! @IBOutlet weak var labelTemp: UILabel! var weatherData :Weather?{ didSet{ confView() } } func confView(){ labelCity.text = self.weatherData?.city }}I'm a swift beginner. The function named confView( ) is called by weatherData before the declaration statement. Is it right? The xCode didn't report an error. But i think "func confView()"should be placed before "var weatherData". Is it necessary?
2
0
566
Feb ’20