UISearchBar in UINavigationBar changes width when rotating orientation - uinavigationcontroller

This is driving me crazy. I am creating a splitview app on iPad.
I have created a searchBar inside the UINavigationBar - something like this...
UISearchBar *searchBar = [[UISearchBar alloc] initWitFrame:CGRectZero];
[searchBar setPlaceHolder:#"Search"];
[searchBar sizeToFit];
[searchBar setDelegate:self];
[self.navigatioItem setTitleView:searchBar];
this works just fine for me displaying the UISearchBar like this...
I also have this UIBarButtonItem set to show Master navigation controller in sidepane.
The problem happens when the device rotates to landscape and the UIBarButtonItem gets hidden. Then the searchBar appears like this...
there is some space on sides which appears to be there since the barButtonItem got hidden and the size of search bar couldn't be updated.
Furthermore, when I rotate the device again, here's what happens to UISearchBar
How can I update the size of searchbar once it has been added to UINavigationBar. Even using autoResizingMask does not work.
searchBar.autoResizingMask =UIViewAutoresizingFlexibleWidth;
What am I doing wrong over here?

I had about the same problem (it wasn't searchbar, but some UIView), and that's how I solved it:
Try creating it with fixed size that won't change. I mean if your navbar minimum size is (for example) 320pt, and barbutton is about 30pt, and you need searchbar to be placed right in the middle (which, BTW is not standart, AFAIK), you'd have to make it 320 - (30+10)*2 = 240pt. Searchbar would be placed right in the middle and will have enough place left free.
This way it will neither change it's size, nor it will affect other items.
Or I would suggest you placing it at right position, not in the middle.
Hope it helped.

Related

Having trouble resizing a QLabel in a QScrollArea

I'm trying to follow the example at the below link to have a picture (in a qlabel) shown in a scrollable area.
https://doc.qt.io/qt-5/qtwidgets-widgets-imageviewer-example.html
I'm using Qt Designer to make the ui instead of hardcoding everything. So I have a QLabel, in a QWidget (with a grid layout assigned to it), in a QScrollArea.
From the tutorial, they state the following for the sizepolicy of the QLabel:
We set imageLabel's [QLabel] size policy to ignored, making the users able to scale the image to whatever size they want when the Fit to Window option is turned on. Otherwise, the default size policy (preferred) will make scroll bars appear when the scroll area becomes smaller than the label's minimum size hint.
Setting it to ignored fits to the window, as expected and as stated. Setting it to preferred provides scroll bars when the image is larger than the scroll area, also as expected and as stated. My issue is that when the sizepolicy is set to preferred, the resize function of the QLabel doesn't work. It always stays at the default size of the loaded image. The only way that I'm able to get the resize function to work is when I don't assign a layout/break the layout to the widget in the QScrollArea, but then no scrollbars will appear when the image is larger than the QScrollArea.
Does anyone have any ideas of how to make the resize function and scrollbars work at the same time?
Thanks in advance for any help. I'm trying to learn qt5 still and this seems like it'd be a simple thing to do, but it's slowly driving me crazy.

iOS 13 UITableViewCell | Child view gets clipped out

SO I have a UITableView which contains a UITableViewCell and tableView.header is set to a Parallax Header. The UITableViewCell has certain UIViews which are set as negative constraints from Top and are shown perfectly on iOS-12 whereas when observed on iOS-13 the UIViews showing over Parallax Header are clipped. I have tried all possible solutions but unfortunately it still shows the same. My App is opting out of SwiftUI and still running the old code. I have even tried to change the zIndex of the child UIView but still the same. Here are some snapshots and some code:
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
self.PriceView.layer.zPosition = 1
self.PriceView.bringSubviewToFront(self.contentView)
self.PriceView.setNeedsDisplay()
}
This code is functional for iOS-12 but not iOS-13.
UPDATE:
Apple's changelog/documentation for iOS-13 suggests:
The UITableViewCell class’s contentView property is always laid out
edge-to-edge with adjacent accessories, both on the leading and the
trailing side. This streamlines the layout code so developers who want
the correct default offset no longer have to align their content with
the content view border or the layout margin depending on whether
there is an accessory on the trailing side or not. You should now
always lay out their code on the layout margins of the cell’s content
view to get the default system insets. These insets will be adjusted
automatically based on the accessories visible in the cell to match
the system’s default spacing. (48214114)
This is a bit unclear to me and if someone can help me out here.
Here are the snapshots as to how it is showing in iOS-12 which is required and how it is showing in iOS-13 respectively:
And here observe for iOS-13:
Here is also the Constraint Layout of my UITableViewCell's PriceView:
I need both to be consistent on both OSes. THANK YOU SO MUCH FOR THIS HELP!
Wohoo! I finally figured it out. So before as default it was working on iOS-12 but after iOS-13 and UITableViewCell changes as described in the question, it stopped working. Here is what I did:
Firstly, in the Size Inspector, the ContentView of UITableViewCell was set to Safe Area Layout Guide which I turned off and turned on Safe Area Relative Margins, similarly I did the same for the child, as in the PriceView.
Secondly, in the Attributes Inspector, the ContentView's and UITableViewCell's both had their Autoresize Subviews property turned on, I simply turned it off
And voila! It works. Hope anyone who might have these UITableViewCell issues, please note that now its all relative 😉
Actually, what worked for me was unchecking "clip to bounds" from the attribute inspector for the content view

UISplitViewController - Master popover - Portrait mode: How to custom/remove the border at the very top layer?

Sorry for the confusing title, but I'm not sure the correct name of the border.
I've created the UISplitViewController that looks like exactly the Mail app in iPad. But my UISplitViewController is not the highest controller in controls hierarchy.
My problem is that I need a sponsor banner to be displayed under UINavigationBarController but above the UISplitViewController.
As the image, I could have everything in place, but 1 thing, the border of the Master View popover stays on top of the banner.
As my investigation and testing, the border is neither the popover border, nor the view's border. It appears as the UIViewController border???
How can I change the border's colour or just remove it?
Thanks
-Khang
I finally found the solution.
There is no way to touch the border, because it's a part on UIViewController.
I realized that the MasterView in portrait mode is a UIPopoverController. It should appear on top of existing content. I tried to insert another view (mask, black UIView to cover the border which was staying on top of the black banner) on top of the popover.
I the solution found here. Just added the mask view in portrait mode and removed it in landscape mode.
Hope this helps other guys.

Init QListWidget to show its all content (with no scroll bars)

I was playing with the Config Dialog Example, all was fine. Then I changed something in the right part of the dialog.
Then I found the contentsWidget (QListWidget) in the left part of the dialog became smaller and showed the scroll bars (both Horizontal and Vertical).
I want the QListWidget to show all its content so that no scroll bars are needed.
All items are added at the beginning and fixed. No dynamic.
I guess there is a simply method to let the QListWidget expand to show all its content at the beginning.
Could anyone help me and tell me the magic word?
Here is the code:
contentsWidget = new QListWidget;
contentsWidget->setViewMode(QListView::IconMode);
contentsWidget->setIconSize(QSize(96, 84));
contentsWidget->setMovement(QListView::Static);
contentsWidget->setMaximumWidth(128);
contentsWidget->setSpacing(12);
//contentsWidget->setMinimumWidth(contentsWidget->sizeHintForColumn(0));
//contentsWidget->setMaximumWidth(contentsWidget->sizeHintForColumn(0));
//contentsWidget->adjustSize();
//qDebug()<<contentsWidget->sizeHintForColumn(0);
createIcons();
contentsWidget->setCurrentRow(0);
QHBoxLayout *horizontalLayout = new QHBoxLayout;
horizontalLayout->addWidget(contentsWidget);
horizontalLayout->addWidget(pagesWidget, 1);
I tried contentsWidget->sizeHintForColumn(0), but it didn't work. It was 0. I tried some other methods but nothing worked.
I think you should try:
contentsWidget->setMinimumWidth(128);
This will ensure that no matters what, the size of contentsWidget will always be at least 128, hence large enough to contains the icons.

dynamic resizing of UICollectionView using intrinsic size within an autolayout

I am trying to implement a calendar using UICollectionView which has a similar scrolling behaviour to the built in calendar app when changing months. At the moment the view is flickering as the resize occurs between months.
I am using a UICollectionViewScrollLayout with a UICollectionView with 10000 indexes in 1 section. The cells are filled by calculating the day for an index. The problem I am having is when trying to resize the view to fit the correct number of weeks for the month, the collectionview doesn't appear to draw in the cells quickly enough as the scrolling and view size change happens. Having slowed the animation down, as the view size changes, it appears that cells are being removed too early from the view. This happens both with a reducing and enlarging the view. Ie, as they are about to scroll off the view they are removed before scrolling out of the view.
The layout is all done using autolayout and there is a fixed view above and then a resizable view below. As the size of the collection view changes the view below changes to fill the space. The only way I seem to have managed to achieve this behavior it is by changing the intrinsic size as per the code below. I have tried changing the frame/bounds but it doesn't seem to work with autolayout. Am I going about the resizing of the view in the right way?
Should I be moving the behaviour to the viewcontroller and change the constraints pinning the height instead.
// Scroll the view to the date given.
-(void) moveViewToDate:(NSDate*) date
{
NSIndexPath *indexPath=[self indexPathForFirstDayInMonth:date];
[self scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionTop animated:YES];
[UIView animateWithDuration:0.25f animations:^{
self.isize=[self weeksInViewForDate:date];
[self invalidateIntrinsicContentSize];
[self.superview layoutIfNeeded];
}];
}
-(CGSize)intrinsicContentSize
{
return CGSizeMake(322,self.isize*46);
}
I finally worked out what was going on. Since I was committing an animation which was changing the size of the view and doing a scroll, the two seperate animations where conflicting with each other.
I eventually rewrote the collection using UIScrollView but had the same problem. I got round it by placing the UIScrollView in a UIView. The UIView was resized using a constraint on the height which was animated.

Resources