Can anyone explain exactly when onAppear is called in SwiftUI. Docs say A view that triggers action when this view appears.
When the view with onAppear changes and is thus rendered again is probably clear. But what about:
When one of its child views changes?
When one of its siblings changes?
When its parent changes?
When navigating back in a NavigationView?
When changing back to a tab view that was previously on the screen, but has not otherwise changed?
Any time it appears on the screen?
When app returns from background?
...
Related
I want to embed some SwiftUI in my UIKit-based UI, and unfortunately Apple doesn't provide UIHostingView, only UIHostingController. Can I more or less ignore that controller and just use its view, or do I really need to add it as a child view controller as well? What happens if I don't?
The problem is that finding the parent view controller can be difficult in some contexts. UIView itself doesn't know anything about view controllers, so I'd have to come up with my own way of keeping track of which is the "current" view controller. And I'd rather not do that unless it's actually necessary.
So far in my experiments it's working fine without adding UIHostingController as a child. Device rotation is handled appropriately, and SwiftUI's dark mode override (.colorScheme()) even works through the embedding.
With UIHostingController(rootView:) you just pass in a SwiftUI View.
You can treat it as a UIView by doing:
let myView = UIHostingController(rootView: Text("Hello world!")).view
And then add it as a subview for example:
let parent = UIView()
parent.addSubview(myView)
Ok, so, I have UINavigationController embedded in a UITabBarController. When selecting the tab bar item, I am presented with the UITableView that is the root of the NavController. Selecting an item in the table takes me to the next view (push) where I set values for that item. Upon hitting Save Changes, I pop the user back to the root controller (the table view). However, the UITabBarItem has gone from a tint of Blue back to the default tint of grey. If, while in the second screen, I hit cancel in the NavBar to return to the root, the UITabBarItem is fine, i.e. still selected and tinted blue.
I have tried several approaches including setting the TabBar's selected item on viewWillAppear as well as trying to set the tint in the UITabBarController itself. Nothing seems to fix the issue. What is really interesting is that, in the UITableView's viewDidAppear (the root view) if I set the selected TabBarItem's tint to blue, the resulting color is a dark grey.
If I select another item in the tab bar and then select the first item again, the blue tint returns. It has something to do with the popping back to the root view that is causing this.
Has anyone seen this? Any thoughts?
If you have any modals or pop-ups (such as an AlertView) in either viewWillAppear, viewDidLoad, (or anytime before the view has finally appeared), it will cause the tint to change upon popping a view.
Check your second view controller if it has any such thing.
I've designed a toolbox control. It's inside a CDockablePane object. Since the tools inside it may need to be scrolled, I've created a CScrollView as a child of the pane and have inserted the tools inside it as children. Based on the pane size, scrollbars of the CScrollView object appear properly, but clicking on them doesn't scroll the view. It seems that they're disabled. When I use SS_NOTIFY style when creating the CScrollView, the CScrollView object receives mouse clicks, but when i don't use the style, it doesn't. But it seems that the scroll bars inside the view control don't receive clicks. When mouse hover over them, no visual effect in scroll bars appears. It seems that the scroll bars are disabled, while I've not created nor manipulate them.
What's wrong?
mouse wheel works. click on scrollbars is received by the scroll view, not by the scrollbars. inside handler, i wrote this code:
CScrollBar *pScroll = GetScrollBarCtrl(SB_VERT);
if (pScroll->GetSafeHwnd())
{
...
if is not true. this means that the scroll view has not a scroll bar, but if so, how is it shown?!
any idea?
...
since i didn't get answer, i'm going to clarify my question with a sample code:
https://dl.dropboxusercontent.com/u/4829119/930501%20-%20t3.zip
in this sample, how can i scroll my view as i do with other views like class view and file view?
the sample code screenshot:
https://www.dropbox.com/s/7pu5chpyj9hqeal/Screenshot%202014-07-23%2003.40.26.png
Did you initialize by calling SetScrollSizes? The scroll bars are enabled only when the sizeTotal is larger than the view window size.
I have three QGraphicsView s each one with a different scene.
I am trying to scroll all the views when the user is scrolling one of them.
The scrolling is carried out by the user dragging in the QGraphicsView widget which calls QGraphicsView::scrollContentsBy. (no scrollbars)
My first implementation:
From scrollContentsBy I am calling centerOn for all the other views but this ends up into a recursive call of scrollContentsBy.
My second implementation:
From scrollContentsBy I am calling scroll for all the other views but the view is not updated correctly (missing part of the scene). It does scroll correctly though.
I tried different versions on this but I can't find the solution.
Any idea would be great.
Edit:
I found the answer but I need to wait 3 more hours before to reply to my own question :)
I am glad that in fact I can answer my own question and share the answer with others.
The only thing that you have to do, it is to create 2 scrollbars (one vertical and one horizontal) and to set these two scrollbars for all the QGraphicsView instances. When the user drag one picture all the view receive the same event and scrollContentsBy is called for each view.
Easy when you know.
m_hScrollBar = new QScrollBar(Qt::Horizontal);
m_vScrollBar = new QScrollBar(Qt::Vertical);
m_srcView->setHorizontalScrollBar(m_hScrollBar);
m_srcView->setVerticalScrollBar(m_vScrollBar);
m_dstView->setHorizontalScrollBar(m_hScrollBar);
m_dstView->setVerticalScrollBar(m_vScrollBar);
m_diffView->setHorizontalScrollBar(m_hScrollBar);
m_diffView->setVerticalScrollBar(m_vScrollBar);
when I launch another UITabBarController in a LaunchView, the TTLauncherView is in the page in the original UITabBarController, the Dest Controller is another UITabBarController, but the Original UITabBarController's TabBar can't disappear.
So, in the UI, I have two TabBars, the Original TabBar in the Bottom, the second Dest Controller View display in the screen except the bottom tabbar.
This is not what I want. How to solve this problem to hide the Original TabBar and let the second Dest Controller to display Full Screen?
In the first Controller, I launch second controller by LauncherView button.
You need to hide the tab bar view when pushing the new controller using
controller.hidesBottomBarWhenPushed = YES;
Take a look on this tutorial from three20 wiki, it explains on how to hide the tab bar when pushing another controller.
http://three20.info/article/2010-11-10-Hiding-The-iphone-Tab-Bar-With-TTNavigator