SwiftUI Academy · Ders

Durumla Görünürlüğü Değiştirme

Boole durumunu kullanarak görünümleri gösterin veya gizleyin.

4. ders / 413 adım

Durumla Görünürlüğü Değiştirme, CoddyKit'te ücretsiz bir SwiftUI Academy dersidir. Bu, 4 dersinin 4. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, SwiftUI Academy öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. SwiftUI Academy kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

Show and Hide on Demand

A boolean @State can decide whether a view is visible. Flip it and SwiftUI shows or hides content for you. 👀

@State private var isVisible = false

Conditional Views

Inside body you can use a plain if statement. When the condition is true, SwiftUI includes the view; when false, it leaves it out.

if isVisible {
    Text("Now you see me")
}

A Button to Flip It

Toggle the boolean from a button action. The tiny toggle() method flips true to false and back.

Button("Toggle") {
    isVisible.toggle()
}

Wire It Together

Combine the button and the conditional Text in a VStack. Tapping reveals or hides the message as the state changes.

VStack {
    Button("Toggle") { isVisible.toggle() }
    if isVisible { Text("Hello") }
}

The Full View

Here is the complete view: one boolean, one button, and one conditionally shown Text.

struct PeekView: View {
    @State private var isVisible = false
    var body: some View {
        VStack {
            Button("Toggle") { isVisible.toggle() }
            if isVisible { Text("Hello") }
        }
    }
}

Toggle the Label Text

You can also drive a label from the same boolean, so the button reads Show or Hide depending on the current state.

Button(isVisible ? "Hide" : "Show") {
    isVisible.toggle()
}

Hidden vs Removed

An if statement truly removes the view from the layout. Other views shift to fill the space, unlike just making something transparent.

Keep Space with opacity

If you want a view to disappear but keep its spot, change its opacity instead of removing it with an if.

Text("Hi").opacity(isVisible ? 1 : 0)

Pair It with a Toggle Control

A SwiftUI Toggle control binds directly to the boolean, giving users a switch that flips your state without a custom button.

Toggle("Show details", isOn: $isVisible)

One Boolean, Many Reactions

The same state value can control several views at once. Change it in one place and every dependent view reacts together.

A Smoother Reveal

Wrap the change in withAnimation and the show or hide will fade in nicely. State plus a touch of animation feels polished.

withAnimation { isVisible.toggle() }

Quick Check

How do you make a Text appear only when a boolean state is true?

Recap

A boolean @State plus an if (or opacity) lets you show and hide views. Flip it with toggle and SwiftUI redraws to match. 🔀

Başlamak ücretsiz

Yapay zeka eğitmeniyle Swift öğren — ücretsiz

Tarayıcında gerçek kod yaz ve çalıştır, 7/24 yapay zeka eğitmeninden anında yardım al; web'de ya da uygulamada kaldığın yerden devam et.

Kurslar
30
Dersler
120

Sıkça Sorulan Sorular

“Durumla Görünürlüğü Değiştirme” dersi ücretsiz mi?

Evet — “Durumla Görünürlüğü Değiştirme” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve SwiftUI Academy kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. SwiftUI Academy kursu toplamda 4 dersten oluşur.

“Durumla Görünürlüğü Değiştirme” dersinde ne öğreneceğim?

Boole durumunu kullanarak görünümleri gösterin veya gizleyin. SwiftUI Academy ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

SwiftUI Academy öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te SwiftUI Academy, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 4. dersidir.

“Durumla Görünürlüğü Değiştirme” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu SwiftUI Academy dersinde kod yazıp çalıştırabilir miyim?

Evet. Her SwiftUI Academy dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. Görünümler Neden Durum Gerektirir?
  2. @State Özelliklerini Bildirme
  3. Dokunma Sayacı Oluşturma
  4. Durumla Görünürlüğü Değiştirme
← SwiftUI Academy Sayfasına Dön