Hide Navigation Bar and Tool Bar Safari Style - ios

I have this code:
#pragma mark - UIScrollViewDelegate Methods
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
self.lastOffsetY = scrollView.contentOffset.y;
}
- (void) scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
if (self.canAnimateBars)
[self animeteBars:scrollView];
}
- (void) scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
if(self.canAnimateBars)
[self animeteBars:scrollView];
}
-(void)animeteBars:(UIScrollView *)scrollView {
bool hide = (scrollView.contentOffset.y > self.lastOffsetY);
[self.view layoutIfNeeded];
if (hide)
self.quickLinkToolBarBotom.constant = -44.0;
else
self.quickLinkToolBarBotom.constant = 0.0;
[[self navigationController] setNavigationBarHidden:hide animated:YES];
}
#pragma mark - UIWebViewDelegate Methods
- (void)webViewDidFinishLoad:(UIWebView *)webView {
self.canAnimateBars = YES;
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
NSLog(#"Error: %#", error.localizedDescription);
}
It is working ok, but Would like to archive the same behaviour of the Safari animation.
I have tried this library AMScrollingNavbar but I can't make it work with the Tool Bar.
How can I make the calculations to move the bars while I'm scrolling the Web view like in Safari.
Thanks for the help.

You can use this code. i think this code used for you.
-(void)animeteBars:(UIScrollView *)scrollView {
bool hide = (scrollView.contentOffset.y > self.lastOffsetY);
[self.view layoutIfNeeded];
CGFloat duration = 0.3;
if (hide)
{
[UIView animateWithDuration:duration animations:^{
self.quickLinkToolBarBotom.constant = -44.0;
} completion:nil];
}
else
{
[UIView animateWithDuration:duration animations:^{
self.quickLinkToolBarBotom.constant = 0.0;
} completion:nil];
}
[[self navigationController] setNavigationBarHidden:hide animated:YES];
}

Related

How create NSLayoutConstraint when scrolling UITableView

I have UITableView on SingleView. Table view have constraint left 0, right 0, bottom 0, top 520. I need change top 520 to the 0 when scrolling up, and when scrolling bottom return 520. How can make it.
How change NSLayoutConstraint from scroll in -
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
I was trying to implement the so-but failed
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (scrollView.tag == 1){
if (scrollView.contentOffset.y < pointNow.y) {
self.heightLogTabTableView.constant = 0;
[UIView animateWithDuration:0.5f animations:^{
[self.view layoutIfNeeded];
}];
}else if (scrollView.contentOffset.y > pointNow.y) {
self.heightLogTabTableView.constant = 520;
[UIView animateWithDuration:0.5f animations:^{
[self.view layoutIfNeeded];
}];
}
}
}
Replace [self.view layoutIfNeeded]; in your code by-- [_tableView beginUpdates]; and [_tableView endUpdates];. Also modify your variable pointNow as follows.
#import "ViewController.h"
#interface ViewController (UIScrollViewDelegate){
}
#end
#implementation ViewController
CGPoint pointNow;
- (void)viewDidLoad{
[super viewDidLoad];
pointNow = CGPointMake(0, 0);
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (scrollView.contentOffset.y < pointNow.y) {
self.heightLogTabTableView.constant = 0;
[UIView animateWithDuration:0.5f animations:^{
[_tableView beginUpdates];
[_tableView endUpdates];
}];
}else if (scrollView.contentOffset.y > pointNow.y) {
self.heightLogTabTableView.constant = 520;
[UIView animateWithDuration:0.5f animations:^{
[_tableView beginUpdates];
[_tableView endUpdates];
}];
}
pointNow = scrollView.contentOffset;
}
#end
Try the setNeedsUpdateConstraints method right after you change the constraint constant. Like:
[self.tableView setNeedsUpdateConstraints];
Update -
If I understood you correctly, this is what you are looking for I think :
-(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{
if(self.heightLogTabTableView.contentOffset.y<0){
//it means table view is pulled down like refresh
}
else if(self.heightLogTabTableView.contentOffset.y >= 0) {
//it means table view is being scrolled up
}
}
Hope this helps you.
This single line of code will solve your issue with all top,bottom,left, right constraints to Zero
[self.tableView setContentInset:UIEdgeInsetsMake(520, 0, 0, 0)];
Please try this and it will help you....
-(void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
if (scrollView.tag != 1)
{
return;
}
if(self.heightLogTabTableView.contentOffset.y<0)
{
self.heightLogTabTableView.constant = 0;
[UIView animateWithDuration:0.5f animations:^{
[self.view layoutIfNeeded];
}];
}
else
{
self.heightLogTabTableView.constant = 520;
[UIView animateWithDuration:0.5f animations:^{
[self.view layoutIfNeeded];
}];
}
}
i add global varible CGFloat in my .h file "#property (nonatomic) CGFloat lastScrollOffset;"
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (scrollView.tag == 1){
if (scrollView.contentOffset.y > _lastScrollOffset) {
self.heightLogTabTableView.constant = 0;
[UIView animateWithDuration:0.5f animations:^{
[self.view layoutIfNeeded];
}];
} else if (scrollView.contentOffset.y < _lastScrollOffset) {
self.heightLogTabTableView.constant = self.informationTask.frame.size.height;
[UIView animateWithDuration:0.5f animations:^{
[self.view layoutIfNeeded];
}];
}
_lastScrollOffset = scrollView.contentOffset.y;
}
else if (scrollView.tag == 2){
if (scrollView.contentOffset.y > _lastScrollOffset) {
self.heightCommentTabTableView.constant = 0;
[UIView animateWithDuration:0.5f animations:^{
[self.view layoutIfNeeded];
self.typeCommentView.hidden = NO;
}];
} else if (scrollView.contentOffset.y < _lastScrollOffset) {
self.heightCommentTabTableView.constant = self.informationTask.frame.size.height + 220;
[UIView animateWithDuration:0.5f animations:^{
[self.view layoutIfNeeded];
self.typeCommentView.hidden = YES;
}];
}
}
}

Improve tabBar animation when hidden

I've think about how to make the tabBar 's hidden animation more elegant and smoothly:
Here is how I implement:
So I just want to improve the animation, while the tabBar is suddenly, you know, disappear and hidden.
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
[self.tabBarController.tabBar setHidden:YES];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
[self.tabBarController.tabBar setHidden:NO];
}
Any suggestion?
Try adding this method:
- (void)setTabBarHidden:(BOOL)tabBarHidden animated:(BOOL)animated
{
if (tabBarHidden == _isTabBarHidden)
return;
CGFloat offset = tabBarHidden ? self.tabBarController.tabBar.frame.size.height : -self.tabBarController.tabBar.frame.size.height;
[UIView animateWithDuration:animated ? 0.6 : 0.0
delay:0
usingSpringWithDamping:0.7
initialSpringVelocity:0.5
options:UIViewAnimationOptionCurveEaseIn|UIViewAnimationOptionLayoutSubviews
animations:^{
self.tabBarController.tabBar.center = CGPointMake(self.tabBarController.tabBar.center.x,
self.tabBarController.tabBar.center.y + offset);
}
completion:nil];
_isTabBarHidden = tabBarHidden;
}
Then you can call it like [self setTabBarHidden:YES animated:YES] and [self setTabBarHidden:NO animated:YES] to hide and show your bar, this will move it in and out of the screen instead of just make it instantly dissapear.
Don't forget to add a new bool property isTabBarHidden and also you can play with the values of the animation.

UIWebView not zooming in iOS8

I want to zooming in out in WebView.I am newer in iOS.Please Help me.Some one say it is default property of WebView.I am testing in iOS8 . It does not work for me.
self.myWebView= [[UIWebView alloc] init];
[self.myWebView setScalesPageToFit:YES];
[self.myWebView setDelegate:self];
[self.myWebView.scrollView setDelegate:self];
[self.myWebView setDataDetectorTypes:UIDataDetectorTypeNone];
[self.myWebView.scrollView setBounces:NO];
[self.myWebView.scrollView setShowsHorizontalScrollIndicator:NO];
[self.myWebView.scrollView setShowsVerticalScrollIndicator:NO];
[myScrollView addSubview:self.myWebView];
- (void)webViewDidFinishLoad:(UIWebView *)theWebView
{
self.myWebView.scrollView.delegate = self;
self.myWebView.scrollView.maximumZoomScale = 20; // set as you want.
self.myWebView.scrollView.minimumZoomScale = 1; // set as you want.
}
(void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale
{
self.myWebView.scrollView.maximumZoomScale = 20;
}
if u are not use viewForZoomingInScrollView they work automatically. if you are use viewForZoomingInScrollView
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
if (scrollView ==myWebView.scrollView){
return self.myWebView;
}
else
{
return nil;
}
}

Options appear when tap on UIImageView

In Apple iOs photos app, Each picture take the full screen, but when You tap on it, navigation bar and tab bar with some menu options (like share picture) just appear and remain for a couple of secconds. How can I do that in my UIImageView ?
Add a UITapGestureRecognizer to your view and UiView for your topbar and bottom bar or what else you like and follow below code. I think This may help you.
//Write below code in ViewDidLoad
UITapGestureRecognizer *singleTapOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleSingleTap:)];
singleTapOne.numberOfTouchesRequired = 1; singleTapOne.numberOfTapsRequired = 1; singleTapOne.delegate = self;
[self.view addGestureRecognizer:singleTapOne]; [singleTapOne release];
for (UIGestureRecognizer *gR in self.view.gestureRecognizers) {
gR.delegate = self;
// handleSingleTap Method
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer
{
if (recognizer.state == UIGestureRecognizerStateRecognized)
{
CGRect viewRect = recognizer.view.bounds; // View bounds
CGPoint point = [recognizer locationInView:recognizer.view];
CGRect areaRect = CGRectInset(viewRect, TAP_AREA_SIZE, 0.0f); // Area
if (CGRectContainsPoint(areaRect, point)) // Single tap is inside the area
{
if ((m_CtrlViewTopBar.hidden == YES) || (m_CtrlViewBottomBar.hidden == YES))
{
[self showToolbar:m_CtrlViewTopBar];
[self showToolbar:m_CtrlViewBottomBar]; // Show
}
else
{
[self hideToolbar:m_CtrlViewTopBar];
[self hideToolbar:m_CtrlViewBottomBar];
}
return;
}
CGRect nextPageRect = viewRect;
nextPageRect.size.width = TAP_AREA_SIZE;
nextPageRect.origin.x = (viewRect.size.width - TAP_AREA_SIZE);
if (CGRectContainsPoint(nextPageRect, point)) // page++ area
{
//[self incrementPageNumber]; return;
}
CGRect prevPageRect = viewRect;
prevPageRect.size.width = TAP_AREA_SIZE;
if (CGRectContainsPoint(prevPageRect, point)) // page-- area
{
//[self decrementPageNumber]; return;
}
}
}
- (void)hideToolbar:(UIView*)view //Hide Toolbars
{
#ifdef DEBUGX
NSLog(#"%s", __FUNCTION__);
#endif
if (view.hidden == NO)
{
[UIView animateWithDuration:0.25 delay:0.0
options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction
animations:^(void)
{
view.alpha = 0.0f;
}
completion:^(BOOL finished)
{
view.hidden = YES;
}
];
}
[timer invalidate];
timer=nil;
}
- (void)showToolbar:(UIView*)view //Show Toolbars
{
#ifdef DEBUGX
NSLog(#"%s", __FUNCTION__);
#endif
if (view.hidden == YES)
{
[UIView animateWithDuration:0.25 delay:0.0
options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction
animations:^(void)
{
view.hidden = NO;
view.alpha = 1.0f;
}
completion:NULL
];
if (!timer) {
timer=[NSTimer scheduledTimerWithTimeInterval:5
target:self
selector:#selector(HideToolBarWithTime)
userInfo:nil
repeats:YES];
}
}
[self.view addSubview:view];
}
-(void)HideToolBarWithTime //Hide Toolbars with time
{
[self hideToolbar:m_CtrlViewTopBar];
[self hideToolbar:m_CtrlViewBottomBar];
[timer invalidate];
timer=nil;
}
// Gesture Delegates
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
return YES;
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}

UIScrollView Snapping with OpenGL GLKit

This has been a bit of a interesting one.
So I have a OpenGl screen with a scrollview on top. I Use a CADisplay link to update the render when I scroll (code below) which works really well.
However, I can't get it to snap to a point (animated). I believe the releasing of the CADisplay link stops the animation of the scrollview (see snapToItem).
I tried firing off the release of the CADisplay 2 seconds after but that causes other issues.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
moveFactor = 0 - (((self.scrollView.contentSize.height - self.scrollView.frame.size.height) - self.scrollView.contentOffset.y) / itemScrollViewMoveFactor);
[self updateLabelPositionScale];
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
[self startDisplayLinkIfNeeded];
}
- (void)snapToItem
{
NSLog(#"%d", self.selectItem);
[self.scrollView setContentOffset:CGPointMake(0, (self.scrollView.contentSize.height - self.scrollView.frame.size.height) - (itemScrollViewHeight * self.selectItem)) animated:YES];
//[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:#selector(stopDisplayLink) userInfo:nil repeats:NO];
[self stopDisplayLink];
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
if (!decelerate)
{
[self snapToItem];
}
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
[self snapToItem];
}
#pragma mark Display Link
- (void)startDisplayLinkIfNeeded
{
if (!self.displayLink)
{
self.displayLink = [CADisplayLink displayLinkWithTarget:self.view selector:#selector(display)];
[self.displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:UITrackingRunLoopMode];
}
}
- (void)stopDisplayLink
{
if (self.displayLink)
{
[self.displayLink invalidate];
self.displayLink = nil;
}
}
Did you try adding the display link to NSRunLoopCommonModes?

Resources