首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在忽略安全区域的容器大小更改时,SwiftUI TabView将失去选择

在忽略安全区域的容器大小更改时,SwiftUI TabView将失去选择
EN

Stack Overflow用户
提问于 2022-10-10 09:27:17
回答 1查看 134关注 0票数 2

我需要忽略TabView的安全区域,这样不同页面中的ScrollView就会在安全区域之外显示可滚动的内容。

当容器的安全区域发生变化时(例如,当显示键盘时),视图将被重新绘制,其选择状态丢失。

代码语言:javascript
运行
复制
2022-10-10 17:18:13.762064+0800 SafeArea[73226:7824972] The behavior of the UICollectionViewFlowLayout is not defined because:
2022-10-10 17:18:13.762259+0800 SafeArea[73226:7824972] the item height must be less than the height of the UICollectionView minus the section insets top and bottom values, minus the content insets top and bottom values.
2022-10-10 17:18:13.762567+0800 SafeArea[73226:7824972] The relevant UICollectionViewFlowLayout instance is <_TtC7SwiftUIP33_8825076C2763A50452A210CBE1FA4AF012PagingLayout: 0x7f8509c0a680>, and it is attached to <_TtC7SwiftUIP33_8825076C2763A50452A210CBE1FA4AF020PagingCollectionView: 0x7f850b037400; baseClass = UICollectionView; frame = (0 0; 393 612.667); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x6000009fa550>; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <CALayer: 0x6000007d4ac0>; contentOffset: {0, 0}; contentSize: {786, 726.33333333333337}; adjustedContentInset: {0, 0, 21.267423644046971, 0}; layout: <_TtC7SwiftUIP33_8825076C2763A50452A210CBE1FA4AF012PagingLayout: 0x7f8509c0a680>; dataSource: <_TtC7SwiftUIP33_8825076C2763A50452A210CBE1FA4AF011Coordinator: 0x60000359c5a0>>.
2022-10-10 17:18:13.763934+0800 SafeArea[73226:7824972] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.

复制代码:

代码语言:javascript
运行
复制
import SwiftUI

struct ContentView: View {
    
    @State var selection = 0
    
    var body: some View {
        VStack {
            Text("An app")
            TabView(selection: $selection) {
                ScrollView {
                    TextField("First textfield", text: .constant(""))
                }
                .background(.blue)
                .tag(0)
                
                ScrollView {
                    TextField("Second textfield", text: .constant(""))
                }
                .background(.red)
                .tag(1)
            }
            .tabViewStyle(.page)
            .ignoresSafeArea(.container, edges: .bottom)
        }
    }
}

简单地删除.ignoresSafeArea(.container, edges: .bottom)可以阻止视图的选择丢失,但也会失去ScrollView在安全区域之外显示其内容的能力。

我做错什么了吗,还是SwiftUI出了问题?在用Xcode 14构建iOS 16之前,我没有注意到它,所以有一些变化或者是坏了:D。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-11-13 05:25:00

苹果已经证实,这是Xcode 14的回归,Xcode 14现在已经修正了Xcode 14.1。

https://feedbackassistant.apple.com/feedback/11684856

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74012744

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档