这是一个有用的例程,当您想知道正在创建的内容以及它的位置时,您可以在iOS应用程序中使用该例程来遍历视图层次结构.
此例程将视图层次结构转储到NSLog()
从传入的视图开始.子视图在子视图数组中显示它们的索引,所有超类按顺序用冒号分隔,最后是帧大小.
要转储应用程序的整个视图层次结构,请调用以下方法:
dumpViews([[UIApplication sharedApplication] keyWindow], @"", @"");
Run Code Online (Sandbox Code Playgroud)
要显示摄像机视图的层次结构,请在控制器中覆盖此方法: navigationController:willShowViewController:viewController:animated:
并像这样调用转储例程:
dumpViews(self.modalViewController.view, @"", @"");
Run Code Online (Sandbox Code Playgroud)
对于所有其他观点:
dumpViews(myView, @"", @"");
Run Code Online (Sandbox Code Playgroud)
void dumpViews(UIView* view, NSString *text, NSString *indent)
{
Class cl = [view class];
NSString *classDescription = [cl description];
while ([cl superclass])
{
cl = [cl superclass];
classDescription = [classDescription stringByAppendingFormat:@":%@", [cl description]];
}
if ([text compare:@""] == NSOrderedSame)
NSLog(@"%@ %@", classDescription, NSStringFromCGRect(view.frame));
else
NSLog(@"%@ %@ %@", text, classDescription, NSStringFromCGRect(view.frame));
for (NSUInteger i = 0; i < [view.subviews count]; i++) …
Run Code Online (Sandbox Code Playgroud) 每当我创建类似Button
和TextView
中的视图时ConstraintLayout
,它们都会卡在顶角而不是我放置的位置.
我尝试创建新活动并更改模拟器,但结果仍然相同.
这是正在发生的事情的屏幕截图:
可能是什么问题?
android android-layout android-view view-hierarchy android-constraintlayout
是否可以在LinearLayout中显示与第二个重叠的第一个视图?
我想像我这样布局我的观点:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentRight="true" >
<TextView
android:id="@+id/firstTextView"
android:layout_width="wrap_content"
android:layout_height="wrapContent" />
<TextView
android:id="@+id/secondTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
但我需要从布局第一个视图firstTextView放置在(重叠)secondTextView的顶部.这可能吗?我正在使用LinearLayout,因为我也在使用边距来获得重叠效果.
我有一个应用程序,它有 UITabbarController 作为初始窗口(登录后我将它设置为 rootViewController)
这个 tabbarController 有 4 个不同的选项卡,它们都是嵌入在 UINavigationController 中的 UIViewController。
在我的 tabbarController 中,当我进行初始配置时,我设置了如下选项卡:
首先我创建viewControllers:
let tableViewController1 = tableViewController1(nibName: "tableViewController1", bundle: nil)
let tableViewController2 = tableViewController2(nibName: "tableViewController2", bundle: nil)
let tableViewController3 = tableViewController3(nibName: "tableViewController3", bundle: nil)
let profileViewController = ProfileViewController(nibName: "ProfileViewController", bundle: nil)
Run Code Online (Sandbox Code Playgroud)然后我将它们嵌入到 navigationControllers 中:
let navController1 = UINavigationController(rootViewController: tableViewController1)
let navController2 = UINavigationController(rootViewController: tableViewController2)
let navController3 = UINavigationController(rootViewController: tableViewController3)
let navController4 = UINavigationController(rootViewController: profileViewController)
Run Code Online (Sandbox Code Playgroud)最后,将 navigationControllers 添加为 tabbarController 的 viewControllers
viewControllers = [navController1,navController2,navController3,navController4]
我在网上查了一下,这种使用方式似乎是正确的。例如:https : //medium.com/@ITZDERR/uinavigationcontroller-and-uitabbarcontroller-programmatically-swift-3-d85a885a5fd0 …
crash uinavigationcontroller childviewcontroller view-hierarchy swift
我正在为自动化制作SKD.所以我的需求与正常的应用程序开发略有不同.
要求:获取当前活动的ViewHierarchy. 问题:当Spinner未打开时,我认为它是正确的.旋转器打开时我没有得到旋转器的细节.
我使用以下代码来获取层次结构.问题是:Spinner是否在不同的窗口中托管,这就是为什么我没有得到它?得到它的方法是什么?
//This is how I start recursion to get view hierarchy
View view = getWindow().getDecorView().getRootView();
if (view instanceof ViewGroup) {
ViewGroup group = (ViewGroup) view;
dumpViewHierarchyWithProperties( group, 0);
}
//Functions to get hierarchy
private void dumpViewHierarchyWithProperties(ViewGroup group,int level) {
if (!dumpViewWithProperties(group, level)) {
return;
}
final int count = group.getChildCount();
for (int i = 0; i < count; i++) {
final View view = group.getChildAt(i);
if (view instanceof ViewGroup) {
dumpViewHierarchyWithProperties((ViewGroup) view, level …
Run Code Online (Sandbox Code Playgroud) 在尝试调试我的视图层次结构时,出现以下错误:
Error: Unable to capture view hierarchy.
Details: No plist data for fetching view hierarchy: error evaluating expression “(id)[(Class)objc_getClass("DBGViewDebuggerSupport_iOS") fetchViewHierarchyWithOptions:(id)[(Class)objc_getClass("NSDictionary") dictionaryWithObjects:(id)[(id)[(id)[(Class)objc_getClass("NSArray") arrayWithObject:(id)[(Class)objc_getClass("NSNumber") numberWithBool:1]] arrayByAddingObject:(id)[(id)[(Class)objc_getClass("NSArray") arrayWithObject:@"_UIVisualEffectBackdropView"] arrayByAddingObject:@"_UIBackdropEffectView"]] arrayByAddingObject:(id)[(Class)objc_getClass("NSNumber") numberWithBool:0]] forKeys:(id)[(id)[(id)[(Class)objc_getClass("NSArray") arrayWithObject:@"DBGViewDebuggerUseLayersAsSnapshots"] arrayByAddingObject:@"DBGViewDebuggerEffectViewsToSnapshotAsImage"] arrayByAddingObject:@"DBGViewDebuggerAlwaysEncodeLayers"]]]”: error: Expression can't be run, because there is no JIT compiled function
Method: -[DBGAbstractViewDescriber handleFetchedViewInfo:fetchError:resultHandler:]
Please file a bug at http://bugreport.apple.com with this warning message and any useful information you can provide.
Run Code Online (Sandbox Code Playgroud)
在iPhone 6 10.2和iPhone 5C 9.3.5上发布.XCode是8.2.1.Mac机是Sierra 10.12.2(16C67).
始终可重复 - 永远不会让它发挥作用.
有人知道吗?
这个问题已在这里提出,但它没有解决方案.
我有一个WebView
.我想将最小高度设置为WebView
using minHeight
属性,但它不起作用.相同的属性适用于Button.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.anshul.webview.WebActivity">
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="400dp"></WebView>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:minHeight="150dp"
android:text="This is a Button. It's minHeight is set to 150 dp and it works !!"/>
Run Code Online (Sandbox Code Playgroud)
显然,从下图中,WebView不支持该minHeight
属性.有谁知道这个问题的解决方案?
我在视图中有一个列表(将其称为视图A),在其中我通过导航链接从视图A推入视图B,并将CurrentSubjectValue操纵到初始视图A。添加数据并添加didChangd.send(value)分派到视图AI的警告是更新不属于视图的单元格。似乎从窗口中删除了视图A,这基于我以前的uinavigationviewcontroller行为是不直观的。任何的想法?
视图A(MainView)
struct MainView: View {
@ObjectBinding var currentProfileIdStore = CurrentProfileIdStore.shared
var body: some View {
NavigationView {
if (currentProfileIdStore.didChange.value == nil) {
NavigationLink(destination: ProfilesView()){ Text("show profiles view")}
} else {
List {
Section {
ForEach(0..<1) { _ in
PresentationLink(destination: ProfilesView()) {
Text("Profiles")
}
}
}
Section {
ForEach(0..<1) { _ in
Text("Items")
}
}
}.listStyle(.grouped)
}
}.navigationBarTitle(currentProfileIdStore.didChange.value ?? "unknown")
}
}
Run Code Online (Sandbox Code Playgroud)
然后显示配置文件视图
struct ProfilesView : View {
@ObjectBinding var profileManager = CurrentProfileIdStore.shared
@ObjectBinding var profileProvider = ProfileProvider.shared
var body: …
Run Code Online (Sandbox Code Playgroud) 我有一个相对布局 R1 作为可扩展列表视图的自定义视图。
现在在 R1 中,我有一个图像视图 I1 和另一个相对布局 R2,两者都是兄弟姐妹。
我已经为 R2 和 I1 设置了点击侦听器。一切正常。但我想在某些触摸条件下移动整个自定义视图 R1。所以我为 R1 设置了 OnTouchListener。但是当我触摸列表项时,R1 永远不会收到它。
我试过搜索,但没有任何效果。有人可以帮我弄清楚如何让 R1 接收到触摸事件,然后如果它不使用它,那么它应该传递给 I1 和 R2。
谢谢,阳光
android expandablelistview ontouchlistener view-hierarchy android-relativelayout
长话短说:
我想在(父)状态发生变化时触发一个操作。这在声明性上下文中似乎很困难。
评论
这里的挑战是我并不试图使一种视图的属性依赖于另一种视图。这是一个覆盖良好的领域。我可以(并且已经)整天阅读有关共享状态更改的内容。但这是一个事件。
我遇到的最好的是arsenius的。他的方法确实有效。我想知道是否有一种更具反应性的方法来做到这一点。也许是一击Publisher
?看起来很粗略。
代码
在 FRP 中,“事件”并不总是一个肮脏的词。我可以通过处理相同的View
事件来启动动画: View
import SwiftUI
struct MyReusableSubview : View {
@State private var offs = CGFloat.zero // Animate this.
var body: some View {
Rectangle().foregroundColor(.green).offset(y: self.offs)
// A local event triggers the action...
.onTapGesture { self.simplifiedAnimation() }
// ...but we want to animate when parent view says so.
}
private func simplifiedAnimation() {
self.offs = 200
withAnimation { self.offs = …
Run Code Online (Sandbox Code Playgroud) view-hierarchy ×10
android ×5
ios ×2
swiftui ×2
android-view ×1
animation ×1
cocoa-touch ×1
crash ×1
debugging ×1
java ×1
list ×1
objective-c ×1
overlap ×1
swift ×1
warnings ×1
webview ×1
xcode8 ×1