Is there option of that to enable/disable it when person touch the clock of statusbar the app go to the top of viewController.
I created an app the main viewController doesn't work and others it works well, I didn't know if it is an option or API?
Thanks in advance.
If you're talking about a UIScrollView or UITableView.
Then you need to implement the following method from the UIScrollViewDelegate or UITableViewDelegate.
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView {
return YES; // Will now scroll to the top when touching the statusBar
}
Related
I want to hide/show navigationBar of a UINavigationController when the WKWebView zooms out/in.
To hide or show a UINavigationBar is quite easy as follows:
self.navigationController?.navigationBarHidden = true
But the problem is that I don't know where to put the code.
I am thinking to intercept the zoom event of WKWebView. May be there are other ways, any comments are welcome.
Every WKWebView has a scrollView property which allows you to access the UIScrollView part of the the web view. You can use the UIScrollViewDelegate method, scrollViewDidScroll to get callbacks on when the web view scrolls.
First, set the scroll view delegate:
let webView = WKWebView(...)
webView.scrollView.delegate = self
Then, implement the delegate method scrollViewDidScroll and add the logic to hide and show the navigation bar:
extension YourClass: UIScrollViewDelegate {
func scrollViewDidScroll(scrollView: UIScrollView) {
// you can use the position of the scrollView to show and hide your nav bar here
}
}
I found another way to achieve it:
self.navigationController?.hidesBarsOnSwipe = true
iOS 8.0 gives UINavigationController a simple property that masks some complex behavior. If you set hidesBarsOnSwipe to be true for any UINavigationController, then iOS automatically adds a tap gesture recognizer to your view to handle hiding (and showing) the navigation bar as needed. This means you can mimic Safari's navigation bar behavior in just one line of code.
I need the tab bar to be n the bottom and scroll left right. Also if scrolled upwards it should expand as a view.
You may need to create a custom tabbar. Add a scrollbar and custom buttons at the bottom.
There are few controls available.
Also you can refer this link :
Making the tab bar scrollable in iphone?
You can use this lib to achieve your goal
https://github.com/Moblox/MBXPageViewController
Implement 3 method of delegate
- (NSArray *)MBXPageButtons
{
return self.segmentButtons;
}
- (UIView *)MBXPageContainer
{
return self.containerView;
}
- (NSArray *)MBXPageControllers
{
// The order matters.
return #[your_tabs_controllers_array];
}
And replace your tab bar with uiviewController with buttons on the bottom. it could save your time
When in landscape, I would like the content of the UIPageViewController to be full screen, and I want to hide the page indicators. In portrait, I want to show the page indicators.
I know that implementing the data source methods are what make the page indicators show/not show (see https://stackoverflow.com/a/20749979/1103584), but as I stated earlier, I want to be able to selectively hide them depending on the orientation of my app.
How can I do this? I've seen it in other apps before (the graphs in App Annie) so I know it's possible. An answer where you iterate through subviews of the UIPageViewController to find an instance of UIPageControl sounds like a very hacky solution to me...there must be a more "official" way to do it.
Thanks in advance.
Currently, there is no way to change the default behavior of UIPageViewController's page indicator after the setViewControllers:direction:animated:completion: method is called. Hopefully, a similar method to hiding a navigation bar will be added in a future update.
Try adding this to your code...
- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration
{
[super willAnimateRotationToInterfaceOrientation:orientation duration:duration];
UIPageControl *pageControl = [UIPageControl appearance];
if (UIInterfaceOrientationIsLandscape(orientation))
{
pageControl.alpha = 0;
}
else if (UIInterfaceOrientationIsPortrait(orientation))
{
pageControl.alpha = 1;
}
}
How I can achieve this effect?
This isn't immediately noticeable from your screenshots, but I believe you want the that header toolbar to slide up as the user scrolls, right? (I'd suggest clarifying on that part)
You can do this a few ways, and in all of them you will have to implement your own scrolling logic, meaning how much the header toolbar slides up depending on where you have scrolled. That said, here's how to do it:
1. If you're using UITableView, I assume you've got your view controller set as its delegate. Since UITableView is a subclass of UIScrollView already, just add the UIScrollViewDelegate to your view controller. That will give us scroll events as they happen. You'll want to do your logic in scrollViewDidScroll:.
2.. If you're simply using UIScrollView, just set your view controller as its delegate, implement UIScrollViewDelegate, and do your logic in scrollViewDidScroll:.
That said, your code might look something like this:
- (void) scrollViewDidScroll:(UIScrollView *)scrollView {
CGPoint scrollPos = scrollView.contentOffset;
if(scrollPos.y >= 40 /* or CGRectGetHeight(yourToolbar.frame) */){
// Fully hide your toolbar
} else {
// Slide it up incrementally, etc.
}
}
Anyway, hope I helped.
If you have properly set the delegate, your table will call scrollViewDidScroll: when scrolled.
So in your controller, you can add something like :
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView.contentOffset.y >0) //means that the user began to scroll down the table
{
[UIView animateWithDuration:0.4 animations:^{
//animations you want to perform
}];
}
}
Here i implemented code for UIView Hide / Show when tableview scrolling. When tableview scrolling down then UIView is hidden and when scrolling up then UIView show. I hope it's working for you...!
Step 1:- Make one property in .h file
#property (nonatomic) CGFloat previousContentOffset;
Step 2:- Write down this code in scrollViewDidScroll Method.
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat currentContentOffset = scrollView.contentOffset.y;
if (currentContentOffset > self.previousContentOffset) {
// scrolling towards the bottom
[self.subButtonView setHidden:YES];
} else if (currentContentOffset < self.previousContentOffset) {
// scrolling towards the top
[self.subButtonView setHidden:NO];
}
self.previousContentOffset = currentContentOffset;
}
I create simple class for this effect:
UIHidingView is an iOS class that displays UIView element on top UITableView which is hiding when Table View is scrolling.
This will answer your question :
iPhone: Hide UITableView search bar by default
same concept, different control. You can put a UIView on top row of tableview or any other relevant control such as button.
Good luck.
I'm using an app with a tableView that auto-scrolls downward, so tapping the status bar, which would normally jump to the top of the table, causes problems (it begins scrolling but if the auto-scroll ticks, it stops and leaves it somewhere in the middle).
I'd either like to disable it, or at least have shove some code in when it's tapped to temporarily pause the timer and then resume it when it reaches the top.
Are there any means of achieving either of these things?
UIScrollView (and UITableView as a subclass of it) has scrollsToTop property which defaults to YES, making it scroll to top when status bar is tapped. All you have to do is set it to NO.
However, please keep in mind that iOS users might expect this behavior, so turning it off may not be the best idea from user experience standpoint. You can also leave it as YES and return NO from -scrollViewShouldScrollToTop: delegate method if you only need it disabled at specific times.
Actually, handling it via delegate might be a perfect fit for your case:
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView
{
// disable timer
return YES;
}
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView
{
// re-enable timer
}
You can try:
[myView setScrollsToTop:NO];
For swift 5
func scrollViewShouldScrollToTop(_ scrollView: UIScrollView) -> Bool {
return false
}