How to use and ignore the Safe Area in SwiftUI | Bootcamp #17

Поділитися
Вставка
  • Опубліковано 22 сер 2024

КОМЕНТАРІ • 78

  • @tommo0
    @tommo0 11 місяців тому +19

    for those who are lost: in the latest versions of swift/xcode, you should never use .ignoringSafeArea, and this entire video can be skipped in 2023. when you move a frame or stack or view to an edge, it will automatically make the background color "bleed" out into the unsafe areas for you.

    • @biffbiffson7350
      @biffbiffson7350 5 місяців тому +1

      Thank you for posting that!

    • @wahhmann123
      @wahhmann123 Місяць тому

      No longer need to use the ZStack trick?

  • @yourbestsail
    @yourbestsail Рік тому +13

    Its looks like the safe area is not working like that anymore. By default now the background ignores the safe area by default....

  • @Soh965
    @Soh965 2 роки тому +5

    This guy wears helmet because he talks about safe areas.
    The logic is just impeccable. LOVE IT

  • @CMessineo
    @CMessineo 5 місяців тому +2

    Love all the videos so far, but this is the first video that I've come across that seems outdated (even beyond your update at the end). It looks like the 15.x version is smart enough to automatically extend background outside the safe area without needing to add any code. Of course, you could use the .ignoresSafeArea if you wanted your text to appear in those areas.

  • @maxdaelman
    @maxdaelman Рік тому +7

    Just wanna say, I've been following from Bootcamp 1, I am learning a lot and thanks for the amazing videos!

  • @pierrempolet
    @pierrempolet Місяць тому

    the best teacher that i ever had in my life. thank you very much

  • @user-ex4fs7kt8q
    @user-ex4fs7kt8q 2 місяці тому

    You are so kind and thank you for continuing to provide helpful videos even after the iOS14 update.

  • @ConfidentlyRong-jo5yt
    @ConfidentlyRong-jo5yt 2 місяці тому

    Glad I didn't skip this video! Had no idea the .background modifier was a view! You the best! Button video here I come!

  • @pitmanra
    @pitmanra 3 роки тому +4

    15:19 Good to have the update to ignoresSafeArea() . Thanks.

  • @brucknerdevilliers
    @brucknerdevilliers 2 роки тому +14

    Hi Nick - Looks like things have changed. Running Xcode 13.2.1 - Seems like Apple has made things even safer and no need to use .ignoringSafeAreas. In the following code the frame consumes the entire screen in both the Preview and the Simulator, but the other objects are limited to the safe area:

    • @brucknerdevilliers
      @brucknerdevilliers 2 роки тому

      Also works the same with .ignoresSafeArea.

    • @govindsolanki1295
      @govindsolanki1295 Рік тому +1

      @@brucknerdevilliers How we can make our background to be in the safe area ?

    • @user-goldeneunga
      @user-goldeneunga Рік тому +1

      @@govindsolanki1295 Use ZStack

    • @JasonEyermann
      @JasonEyermann Рік тому

      Me too

    • @davidbejo7367
      @davidbejo7367 11 місяців тому

      @@govindsolanki1295 Set ignoresSafeAreaEdges in background to empty array. For example: .background(.red, ignoresSafeAreaEdges: [])

  • @redstonerepeater2476
    @redstonerepeater2476 Рік тому

    Amazing tutorial,
    Ngl, made me chuckle at 7:20 when you said "so before we end this video" with 10 minutes left

  • @kurtschmucker4229
    @kurtschmucker4229 2 роки тому +1

    The examples in this video were especially good. In particular, showing that you can inadvertently place text behind the iPhone notch was a really great example of what not to do. Thanks.

  • @kode561
    @kode561 3 роки тому +3

    You called me right out at 07:00 As I take breaks and practice between videos I always do that edges and padding and thats the sloppiest part of my code I was literally just doing that before this video and testing different iPhones and had to keep adjusting, this vid is beautiful.

    • @SwiftfulThinking
      @SwiftfulThinking  3 роки тому +1

      Haha yea, I used to do the same thing too! I'm happy this helped you out.

    • @kode561
      @kode561 3 роки тому

      Swiftful Thinking i havent got to the core data video yet im on vid 32/54 but a video series on firebase and data and networking would be great

  • @paulraggett7837
    @paulraggett7837 3 роки тому +3

    Good catch on the change after 14.3. Once again excellent product. Thank you.

  • @dmitrygolovin8066
    @dmitrygolovin8066 2 роки тому +10

    Great video Nick! Seems like in Xcode 13, background modifiers ignore safe area by default.

    • @gibber1sh-c6w
      @gibber1sh-c6w Рік тому +1

      How do we solve this problem?

    • @kamaldeepsinghbhatia1472
      @kamaldeepsinghbhatia1472 10 місяців тому

      @@gibber1sh-c6w we need to pass an empty array for that e.g. `.background(Color.red, ignoresSafeAreaEdges: [])` this will ensure that the color stays within safe area
      Just wanted to add, I tried it on "Text" so I found that my text is staying within safe area and it's just the color was going beyond. Here's what I'm doing -
      VStack {
      Text("Hello, World!")
      Spacer()
      }
      .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
      .background(Color.red)
      So, Text is staying within safe area but color is ignoring that

  • @sireyck
    @sireyck 11 місяців тому +1

    Hi Nick, thanks for the course, really enjoying it so far. Just wanted to add that something must have changed between when you created it and now as your code's background no longer cuts off at the safe area margins. The background is now extending to the edges of the device without having to specify ignore safe area.

  • @nicholasliu2675
    @nicholasliu2675 3 роки тому +1

    Wonderful! I try a lot of ways to fix the "bug"( I thought apple did not design it well, maybe they made a mistake, I still think so because it is not obviousely easy to use). You use a simple and clear way to fix the problem. Well done! Buddy

  • @ataberkkilinctekin188
    @ataberkkilinctekin188 Рік тому

    Maaan, these beginner contents are amazing. Thanks a lot for all of these videos !!!

  • @soulmood5893
    @soulmood5893 Рік тому

    Best teacher I have seen so far.

  • @kasunjayasekara3052
    @kasunjayasekara3052 3 роки тому +1

    Superb thanks a lot :)

  • @TeemoChan
    @TeemoChan Рік тому +1

    I'm really enjoying Your videos

  • @sema_f
    @sema_f 2 роки тому

    Thanks 🙏 for updating this video …i was wondering…

  • @AADITYAAA
    @AADITYAAA 2 роки тому

    best teacher out there

  • @leneil46
    @leneil46 Рік тому

    You got skills

  • @andrerobillard1082
    @andrerobillard1082 2 роки тому +3

    My .frame covers the whole screen, not just the safe area. I have the same code as you but yours stays with the safe area. I’m on Xcode 13.3.1. Did something change?

  • @moku7787
    @moku7787 7 місяців тому

    Thank you 🔥

  • @user-ev3dl9zt8s
    @user-ev3dl9zt8s 3 роки тому +1

    Thank you!!!

  • @lamsungfai
    @lamsungfai 2 роки тому +3

    Hi Nick
    At 10:00 I found that the red colour in VStack cover whole screen including the safe area. Did something change in swift?

    • @CFthorin
      @CFthorin 2 роки тому +2

      Same here. I'm guessing that the .background just by default ignores the safe area?

    • @911gogogo
      @911gogogo Рік тому

      Same here

  • @vazzhh
    @vazzhh 9 місяців тому

    super nice. pero por suerte en xcode 15 ya no hace falta poner ignoreSafeArea. igual es muy bueno saber todo esto.

  • @jahongirtursunboyev6470
    @jahongirtursunboyev6470 Рік тому

    thanks Nick!

  • @prettygirl6146
    @prettygirl6146 2 роки тому +2

    by default all my views go beyond the safe area. how to prevent this?

  • @Nunny25
    @Nunny25 3 роки тому +1

    Thanks...

  • @eldarsadykov
    @eldarsadykov 2 роки тому

    Thank you!!!!!!!!!!!!!

  • @ZhengCheng
    @ZhengCheng 3 роки тому

    Thank you~

  • @rotorcraft68
    @rotorcraft68 2 роки тому

    Can you explain how to do this on macOS Monterey? I got a 2021 MBP 14" with the "notch" and I want to run a simple window app that shows a color and when going full screen it uses the ENTIRE screen, not just the area below the notch. All attempts at using various methods that work on iOS fail on macOS Monterey as the app is always pushed below the notch into a safe area regardless. The reason I want to do this is to check for dead/stuck pixels at the TOP of the display in that menu bar area on a batch of new 2021 Macs. Thanks!

  • @kainerda2088
    @kainerda2088 2 роки тому +2

    Something is strange here in both examples (Xcode 13.1).. It seems that .background() by default ignores the safe area when attached to a top-level component. Bug or feature, I'm not sure. The question now would be what is the opposite of .edgesIgnoringSafeArea() / .ignoresSafeArea(). Is there something like ".respectsSafeArea ()"? 🤔

    • @SwiftfulThinking
      @SwiftfulThinking  2 роки тому

      Hi Kai, the background does NOT ignore the safe area by default. If your background layer is ignoring the safe area "by default" then it's probably in a view hierarchy where another modifier is forcing it to ignore the safe area lol. There is nothing like "respect safe area" you just need to manage their hierarchy and different layers of the view.

    • @TheVidCat
      @TheVidCat 2 роки тому +5

      Same here! Xcode 13.1. Tried both examples and .background ignores the safe areas by default without needing to specify .edgesIgnoringSafeArea(). I would also want to know what is the cause of that.

    • @raimitis
      @raimitis 2 роки тому +3

      Same for me. Xcode 13.4. Regardless what I do in my case whole screen has red background colour.

    • @dominicklarkin7336
      @dominicklarkin7336 2 роки тому +3

      Same with me. I followed the code he wrote exactly but it just seems to ignore the safe area regardless of if I use the '.edgesIgnoringSafeArea()' or not.

    • @gibber1sh-c6w
      @gibber1sh-c6w Рік тому +1

      ​@@SwiftfulThinkingH'es right. . I copied your code (at 4:44) and it behaves differently on XCode 13.4

  • @jean-michelnogaro7471
    @jean-michelnogaro7471 Рік тому

    Bonjour. J'ai remarqué que le background (Color.red) ne respectait pas la safearea. Par contre le texte .. oui. Je pense qu'il s'agit d'un nouveau réglage des dernières versions de xcode ..
    Hello. I noticed that the background (Color.red) did not respect the safearea. On the other hand the text .. yes. I think this is a new setting of latest versions of xcode..

  • @user-yd9xy3rb4x
    @user-yd9xy3rb4x 3 роки тому

    Hi guys. The question is kinda odd. But anyway, why did we get the method changed if it brings no new functionality ?
    I mean I don't mind, I am just wondering.

  • @simranpreetchahal1270
    @simranpreetchahal1270 Рік тому

    Do you have link to your code used in these videos?

  • @CFthorin
    @CFthorin 2 роки тому

    For me, when I have the scrollview not ignoring the safe area, the rounded rectangles when scrolled vertically travel outside the safe area. How you keep the scrolled items inside the safe area?

    • @SwiftfulThinking
      @SwiftfulThinking  2 роки тому +2

      This is usually a good thing lol but you can use .clipped to clip views to their frame

  • @wa7a1993
    @wa7a1993 2 роки тому

    Hello Nick,
    Thanks for your videos. I would like to know about any features that are not available on old versions, would that be an issue for users, please?

    • @SwiftfulThinking
      @SwiftfulThinking  2 роки тому

      Hi, I'm not sure your question. What type of feature do you want to know about?

    • @wa7a1993
      @wa7a1993 2 роки тому

      @@SwiftfulThinking I'm talking about any new features or modifiers that come to SwiftUI like .ignoreSafeArea that target a specific Version. Does that affect the user of the app after launching or involve only the developer? I hope my question is straightforward :)

  • @pitmanra
    @pitmanra 3 роки тому

    Dude! 10:09 there's that Command-/ described as Back Slash again. Your videos are so perfect otherwise.

  • @offthedeepend762
    @offthedeepend762 2 місяці тому

    This guy is so not funny its funny

  • @knowledgeispower4953
    @knowledgeispower4953 6 місяців тому

    Nice bro

  • @PaulDabit
    @PaulDabit 2 місяці тому

    God bless you brother ❤❤❤❤❤❤ Jesus Christ bless you brother ❤

  • @magedmohmed4403
    @magedmohmed4403 Рік тому

    Thanks again for your hard work , Thank you very much 🤎🤎

  • @Benbbr
    @Benbbr 3 роки тому +4

    You blow me away with the simplicity and practicality of your lessons. Kudo's!
    As 'we' are building our own reference guide, why comment-out code while we can use multiple views/screens in our view struct. Per example a iPhone to go with it, building up the good and bad practice.
    Can't wait to finish the course. 💪🏽