Show/Hide subview from UIStackView inside UITableViewCell is having animation - swift

I have a UIImageView inside of UIStackView in UITableViewCell. Based on some parameters i want to show/hide that imageView.
I do this in cellForItemAt method by setting isHidden parameter on imageView. This works just fine for all but one case. When i do pull to refresh (so reloadData()) on tableView this imageView appears with animation (it slides from left). Is there any way to disable this?
Update:
I noticed that this happens because i have UISearchController in navigationItem.searchController. Not sure if anyone else had this issue before?

Related

tvOS UIImageView Focus Shadow Clipped

I have a UICollectionViewCell in a UICollectionView containing two components
1 x UIImageView
1 x UIView
The UIView would ideally contain a couple of labels, and has the following properties set as default:
backgroundColor = .clear
isHidden = true
The UICollectionView has clipsToBounds set to false.
In the delegate of the UICollectionView, I am using the didUpdateFocusIn function to determine which cell will receive focus next, and un-hide the UIView.
As the UIImageView has the adjustsImageWhenAncestorFocused set to true, there is a drop-shadow drawn by tvOS when it automatically applies the zoom + parallex effect.
As can be see in the two pictures below (the second picture has the UIView's backgroundColor set to .black for clarity), the shadow is clipped by the empty space belonging to the UIView in the cell beside it, even though the UIView is already hidden.
Is there some way that I can resolve this?
Edit: Have added a third image which shows the shadow behaving perfectly when the UIView is totally removed from the .xib.
Well, it turns out that I'm a bumbling fool.
I forgot that I had set the bottom constraint of the UIImageView to be anchored to the top of the UIView that was below it.
The net result of hiding the UIView caused the UIImageView to seek out the bottom of the UICollectionViewCell, and that caused the clipping issues.
I have now constrained the UIImageView to a fixed height, and the problem has been resolved!
Since tvOS 11, there is no need to bind your view constraints to the UIImageView constraints to get that effect.
You can get that effect making use of the new property overlayContentView of UIImageView.
Link to the documentation:
https://developer.apple.com/documentation/uikit/uiimageview/2882128-overlaycontentview
A more elaborated explanation can be found from the minute 15:00 of the following WWDC video:
https://developer.apple.com/videos/play/wwdc2017/209/
If the method offered by Apple to get this effect, is not enough for your specific case, I also recommend this great third party library which basically allows getting a Parallax effect in any UIView.
https://github.com/PGSSoft/ParallaxView

Animations set in collectionView keep reloading

I have a collectionView and each cell has a graph that animates once the collectionView loads. The animation is based on CAShapeLayer animation and the value is being passed from the collectionView.
The animation works somewhat fine for most cells. The two things that I am running into are:
1) When I scroll down and new cells appear, the animation for those newly appeared cells begin, but the progressLabel only appears when the animation is finished (which is odd).
2) When I scroll back to top, cells that previously already animated will partially animate again.
Is there a way to have all cells animate once the view controller loads and prevent any additional animations?
This is a follow-up to my previous question, which has the code I am using for this: Setting toValue for CAShapeLayer animation from UICollectionView cellForItemAt indexPath

UIButton Title not showing inside UIStackView

I created a UIStackView with a UIImageView and a UIButton. The text inside of the UIButton won't show. I can tell that autolayout works because the background and the selection of my UIButton both work properly.
The title always disappears when I have the constraints on. I set the image to 0/0/0/0 without margins and aligned the button to the image's edges.
Has anyone run into this or knows how to fix it?
At the end I simply used a UIView. I don't know what made me use the UIStackView but I guess it's not made for overlaying objects.

Scroll View & UIGestureRecogniser Conflict

I have a UIImageView as subview in my scrollView.
I want to be able to pan up/down on UIImage to adjust the color of the UIImage.
Also I want to be able to pan/zoom around the image(that's why I implemented scrollView).
I have an adjustColor IBAction UIButton which adds the UIPanGestureRecogniser as target and executes the function below:
func panned(gesture: UIGestureRecognizer){
...
}
My problem is that the adjustColor button is ignored by scrollView's scroll behaviour.
If I delete the scrollview and add the UIImage, the adjustColor button activates the color adjustment function and the gestures work perfectly.
On the other hand, if I have the scrollview and the image as subviewimage, my adjustColor button has no functionality.
Any help would be appreciated.
Thank you.
Make sure to connect the UIGestureRecognizer IBOutlet with scrollview.

Resizing UITableView on RootController

Is it possible to resize the UITableView on the RootController of a nav based app? When RootViewController.xib is opened in IB, there isn't a view. Just the UITableView. Clicking the inspector and then the little yellow ruler, frame height is grayed out. I'm adding a toolbar programmatically to the RootViewController:
[toolbar setFrame:rectArea];
That works fine but the bottom cell in the tableview is partially hidden because the tableview doesn't know about the toolbar.
The easiest way, is to adjust the contentInset (which is inherited from UIScrollView). Resizing by setting the frame can cause crazy drawing bugs in cells.
For example, if you are trying to resize a tableview for the keyboard, do something like this:
tableView.contentInset = UIEdgeInsetsMake(0.0, 0.0, 216.0, 0.0);
tableView.scrollIndicatorInsets = tableView.contentInset;
Hope that helps someone. This way worked best for me.
Yes, but you need to have a ViewController (not a UITableViewController) as the root controller for the nav, and wrap the actual UITableView in the UIViewControllers view.
You can still have the UIViewController conform to the UITableViewDelgate and Datasource protocols, and use all the same methods you have now in your UITableViewController.
P.S. you'll get more responses if you use the plain "iphone" tag.
You could also just set the Content and Scroller inset of the tableview
I encountered a similar issue when attempting to display the detail controller by itself, see: http://vimeo.com/13054813
The issue is that the SplitView controller applies its own transform to the sub-controllers, taking them out of the orientation detection loop, which blows goats and seems incredibly 'hackish' for built-in classes. (The video illustrates what happens when you make the detail view the root view, then add it back to the split view and make the split view root while in landscape; you get double rotation of the detail view.)
Unfortunately I've again run into these transformation issues while attempting to resize a SplitViewController's detail sub-view in response to the keyboard appearing/disappearing. In portrait, all works fine, in landscape it's fscked.
Yes, adjust the contentInset and scrollIndicatorInsets are the convenient way to resize the UITableView.
As the answer of Sam Soffes posted, I succeed resize UITableView in UITableViewController for the bottom UIToolbar.