I have views hierarchy in Viewcontroller below. First time when I open the view controller my tableview is not scrolling at all even when I tap on tableview it will not recognize my tap. After that It is working fine as expected. I can able to scroll and select cell and working fine. Only first time I am having issue.
I don't have enough reputation so I can't post image.
ViewController -> View -> ScrollView -> View(viewSC) -> TableView -> TableViewCell
Anyone experiencing this kind of behavior.
Thanks in advance.
EDITED
self.scrollView.contentSize = self.viewSC.frameSize;
self.scrollView.contentInset = UIEdgeInsetsMake(self.HV.frameHeight, 0, 0, 0);
self.scrollView.scrollIndicatorInsets = UIEdgeInsetsMake(self.HV.frameHeight, 0, 0, 0);
this is the only code added in viewDidLoad. Other than that it is all working fine.
Are you trying to scroll as soon as the table view is created? When it comes to UITableView manipulation, you have to make sure that it's created and displayed before you try to scroll it. UITableView is picky like that. If you are loading your view and then you want to scroll the table view, call your code in viewDidAppear, not viewDidLoad.
Related
I'm using a paged scroll view displaying different web views as pages. The scroll view has set clipsToBounds = false to allow the display of previous and following pages in the scroll view.
When scrolling through the pages, there is one exact moment, where the WKWebViews content becomes completely invisible. This happens exactly at the moment, where the web view leaves the bounds of the scroll view (see below). On some websites, the visible content out of the bounds is different to the actual content.
These problems only occur when using WKWebView instead of UIWebView (Everything works as intended with UIWebView).
Has someone experienced similar issues with the WKWebView and has a solution for them?
EDIT:
There is a now a sample project on Github, where you can experience the bug and play around with it:
WKWebView test project
To figure it out i think you need to use UICollectionView.
The cell should exist with WKWebView while it will be on screen.
1) You need to place it like Here
And next problem will be to make content pageble.
2) To do it right you need to add UIScrollView over your collection like Here
3) After, make your UIScrollView pageble and write in viewdidload:
collectionView.addGestureRecognizer(scrollView.panGestureRecognizer)
4) After you receive models for showing in UICOllectionView - update your contentSize of UIScrollView like
scrollView.contentSize = CGSize(width: (models.count*(cellWidth+cellIndent) + sectionIndent * 2), height: cellHeight)
5) Implement UIScrollViewDelegate
extension YourVC: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollView == self.scrollView {
collectionView.contentOffset = scrollView.contentOffset
} else if scrollView == self.collectionView {
self.scrollView.contentOffset = scrollView.contentOffset
}
}
}
Thats it. Happy coding =)
WKWebView is designed to be more performant than UIWebView. It will stop running some parts of a webpage or stop rendering it completely if it is not on top of the view hierarchy. The problem here is that once the webpage is out of the bounds of the scrollview, WKWebView does not consider itself to be on screen even though it is visible by virtue of setting clipsToBounds = false.
The easiest thing to do would be to use UIWebView. If for some reason you need WebKit, consider adjusting you paging code so your scrollview spans the entire view controller.
I have a VC where I created a UITableView and added it to the main view. The table has his delegate and datasource added to the VC:
choicesTableView.dataSource = self
choicesTableView.delegate = self
I can see the table correctly and everything runs smooth.
In cellForRowAtIndexPath I've created a new UITextView and added to cell:
let myTextView = UITextView(frame: CGRectMake(0, 0, myVar.sW, 100))
(myVar.sW is a referenced value token from the screen width)
I added the UITextView to the cell:
cell.addSubview(myTextView)
Again, I see all as expected.
The Dark Side Of The Moon of this situation is that now I cannot get the didSelectRowAtIndexPath event since the UITextView is covering the cell's view. If I comment the addSubview method, the didSelectRowAtIndexPath is correctly fired.
Is there any way to let the UITextView pass the user interaction to the cell without creating a custom cell view from scratch?
(for your information, in this phase I'm not using the Interface Builder)
Thank you.
The solution was pretty simple. I resolved my problem by adding this line:
myTextView.userInteractionEnabled = false
So the touch can pass through the UITextView's layer and reach the cell layer.
This thread has helped me.
Currently i have a chat app utilising a collection view with a input accessoryView at the bottom to type in your messages. when the user types inside the textView, the keyboard is displayed and also dismissed by tapping outside the textView or interactively dismissing the keyboard.
the problem is that when the keyboard is dismissed, the collectionView cells (which contain the messages) correctly move to their new position, however they grow horizontally as they appear with that growth visible to the user. I have identified that this effect occurs during the keyboard animation which I require. Just don't know how to have the collectionViewCells resize in a way that is not visible. The following is the code I am using for the keyboard transition. Any help would be greatly appreciated.
UIView.animateWithDuration(animationDuration, animations: { () -> Void in
self.collectionView.contentInset = UIEdgeInsetsMake(0, 0, intersectionOfKeyboardRectAndWindowRect.size.height, 0)
self.collectionView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, intersectionOfKeyboardRectAndWindowRect.size.height, 0)
})
I think I may need to either invalidate the collectionView layout or layoutIfNeeded but not sure where to do that.
Thank you
I want to move the tableViewCell down a little when the UIView is expanded.
I have some detail information initially hidden inside the view. Now if the users are interested in the detail information, they can click the button on the view to show the detail information, but the frame of detail intrudes onto the tableViewCells, so I want to change the location of tableViewCells to move it down a little to fit the view's frame.
Is possible to change the frame of the cell in the cellForRowAtIndexPath?
I have tried it, but I get an error.
The following picture says when I click the arrow image, it shows the detail information.
Thanks.
Note: My UIView is inside the UITableView, so changing the frame of UITableView doesn't work.
self.tableView.frame = CGRectMake(self.tableView.frame.origin.x,self.detailView.frame.origin.y + self.detailView.frame.size.height,self.tableView.frame.size.width,self.tableView.size.height - x);//set value of x according to your need
I hope this would help.Thankyou
You should change contentInset of the UITableView:
youtableview.contentInset = UIEdgeInsetsMake(x, 0, 0, 0);
You should fix that x value to deal with your custom view height.
Good luck.
You could change the ContentOffset of the UITableView.
self.tableView.contentOffset = CGPointMake(0, self.tableView.contentOffset.y + 44);
I have a UITableView with a UIToolbar-like view at the bottom of the screen. I'd like to dynamically animate the toolbar to slide up and down to appear and disappear on the screen when the user takes certain actions on the table data. The problem I'm encountering is that when I animate the toolbar upward, it covers the last few letters of the index.
I'd like to shrink the index size as an animation, along with the toolbar animation. The standard UITableView index functionality doesn't provide us access to this view, just what the view displays, via sectionIndexTitlesForTableView. What's the best way to go about modifying it in such a way?
One way is to animate the entire table view height. This will also prevent your toolbar from covering basically the last cell in case they wanted to do something with it while the toolbar is up.
If you have a UITableViewController then you might have to move your code into a normal UIViewController.
Another way is to enumerate through the subviews of your table view and find the section title view that way, though I'm not sure if that would work very well.
Remember that UITableView is just another scrollview. Just adjust the contentInset and scrollIndicatorInsets according to your toolbar's height:
UIEdgeInsets contentInset = self.tableView.contentInset;
contentInset.bottom = self.myToolbar.frame.size.height;
self.tableView.contentInset = contentInset;
UIEdgeInsets scrollInset = self.tableView.scrollIndicatorInsets;
scrollInset.bottom = self.myToolbar.frame.size.height;
self.tableView.scrollIndicatorInsets = scrollInset;