Hide navigation bar when double click on UIview - iphone

How to hide the navigationBar on double tap and show on single tap on UIView without using the navigation controller? And also the animations when hiding and showing?
Thanks in advance.

UITapGestureRecognizer* tapGesture =[[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(your_selector)];
tapGesture.numberOfTapsRequired = 2;
[self.view addGestureRecognizer:tapGesture];
[tapGesture release];
In your selector:
-(void)your_selector{
[UIView animateWithDuration:0.5
animations:^{
bar.frame = CGRectOffset(bar.frame, 0, bar.bounds.size.height*bar.frame.origin.y<0?-1:1);
}];
}
In this implementation you have only double-touch event that will change status of bar to reverse.
Unfortunately there are no easy implementation for single and double touché gestures at one moment. Much more human behavior and easy for you - work only with event of double touch.
XCode project - example

You can have a UINavigationBar without a navigation controller:
navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 40.0f)];
[navBar setDelegate:self];
[mainView addSubview:navBar];
UITapGestureRecognizer is a concrete subclass of UIGestureRecognizer that looks for single or multiple taps:
UITapGestureRecognizer *doubleTap =[[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(hideNavBar:)];
[doubleTap setNumberOfTapsRequired:2];
[YOURVIEW addGestureRecognizer:doubleTap];
UITapGestureRecognizer *singleTap =[[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(showNavBar:)];
[singleTap setNumberOfTapsRequired:1];
[YOURVIEW addGestureRecognizer:singleTap];
Here are the methods that show or hide the navigation bar:
- (void)hideNavBar:(id)sender
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0f]; //Animation duration in seconds
navBar.alpha = 0.0f;
[UIView commitAnimations];
}
- (void)showNavBar:(id)sender
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0f]; //Animation duration in seconds
navBar.alpha = 1.0f;
[UIView commitAnimations];
}

try this for hiding
[UIView beginAnimations:#"Hide bar animation" context:NULL];
[UIView setAnimationDuration:0.5];
navigationBar.alpha = 0.0;
[UIView commitAnimations];
for showing
[UIView beginAnimations:#"Show bar animation" context:NULL];
[UIView setAnimationDuration:0.5];
navigationBar.alpha = 1.0;
[UIView commitAnimations];
but with UINavigationController it's too easy...

Related

iOS7 Fullscreen uiview.. why disappear status bar?

(i can't speak english well T.T)
I want fullscreen uiview in uiviewcontroller.
I use this code.
- (IBAction)addBtn:(id)sender {
addView = [[AddView alloc] initWithFrame:CGRectZero];
[[[UIApplication sharedApplication]delegate].window addSubview:addView];
addView.window.windowLevel = UIWindowLevelStatusBar;
[addView setAlpha:0.0f];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.35f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[addView setAlpha:1.0f];
[UIView commitAnimations];
}
when click button (+)
disappear status bar!!!!!!!
when i use same code in ios6, it's worked.
but in ios7 not worked.
why disappear status bar?
check my sorce code here.
write below code in viewdidLoad function...
your code......///
[addView setAlpha:0.5];// make addsubview alpha 0.5
Hope it will work...my friend!!!!
Happy Coding!!!!!!
Hi here is the code for your addBtn Method.
-(IBAction)addBtn:(id)sender {
addView = [[AddView alloc] initWithFrame:CGRectZero];
[[[UIApplication sharedApplication]delegate].window addSubview:addView];
addView.window.windowLevel = UIWindowLevelNormal;
[addView setAlpha:0.0f];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.35f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[addView setAlpha:1.0f];
[UIView commitAnimations];
}
It is working fine now.
You need to remove this line, addView.window.windowLevel = UIWindowLevelStatusBar;
- (IBAction)addBtn:(id)sender {
addView = [[AddView alloc] initWithFrame:CGRectZero];
[[[UIApplication sharedApplication]delegate].window addSubview:addView];
// addView.window.windowLevel = UIWindowLevelStatusBar;
[addView setAlpha:0.0f];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.35f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[addView setAlpha:1.0f];
[UIView commitAnimations];
}

Creating a faded out screen effect iphone

I have a view controller....when the user presses a button I want a black screen to fade in over the top and a uiactivityindicator to appear on top of the faded screen.
How can I get this animated fade in effect?
-(IBAction) loginToApp:(id)sender{
//fade in view
}
Add another view over the top of your view, colored solid black. You can do it in IB or programatically, just make sure it has a higher z-order (is on top). Make its alpha = 0. Then:
-(IBAction) loginToApp:(id)sender{
[UIView animateWithDuration:1.5 animations:^{ myview.alpha = 1.0; }]
}
...obviously you need an outlet or variable myview connected to that view. 1.5 = seconds. Change for your needs.
Sure you can. You can create the overlay view however you wish, but this will work (assuming you create appropriate instance variables somewhere). My code was in my view controller, so [self view] returns the view I want to shade over.
shadeView = [[UIView alloc] initWithFrame:[[self view] bounds]];
shadeView.backgroundColor = [UIColor blackColor];
shadeView.alpha = 0.0f;
spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorStyleWhiteLarge];
spinner.center = CGPointMake(CGRectGetMidX([shadeView bounds]),
CGRectGetMidY([shadeView bounds]));
[shadeView addSubview:spinner];
[[self view] addSubview:shadeView];
To present:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.0];
[spinner startAnimating];
shadeView.alpha = 0.7f;
[UIView commitAnimations];
And to hide:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[spinner stopAnimating];
shadeView.alpha = 0.0f;
[UIView commitAnimations];

How to hide tabbar and navigationbar when tapped on the view

I was building an articles based application,i am having tab bar and navigation bar in my application.What i want to do is while my article is displaying when i tap on that view,the tabbar and navigationbar should hide and viceversa.
Please help me in this
Thanks for the responses,Finally i have used gesture method
UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc]
initWithTarget:self action:#selector(handleDoubleTap)];
doubleTap.numberOfTapsRequired =1;
[scrollView addGestureRecognizer:doubleTap];
[doubleTap release]; - (void)handleDoubleTap {
NSLog(#"Single tap");
if(firstTime)
{
[UIView beginAnimations: #"moveField"context: nil];
[UIView setAnimationDelegate: self];
[UIView setAnimationDuration: 0];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[self.navigationController setNavigationBarHidden:YES animated:YES];
scrollView.frame = CGRectMake(0,0,320,460.0f);
tabBar.hidden=YES;
[self.view bringSubviewToFront:scrollView];
[UIView commitAnimations];
firstTime=NO;
}
else {
[UIView beginAnimations: #"moveField"context: nil];
[UIView setAnimationDelegate: self];
[UIView setAnimationDuration: 0];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
//[self.view bringSubviewToFront:scrollView];
[self.navigationController setNavigationBarHidden:NO animated:YES];
scrollView.frame = CGRectMake(0.0, 0.0, 320, 372);
tabBar.hidden=NO;
[UIView commitAnimations];
firstTime=YES;
}
Now iam getting this when i tap on the screen...Is it possible to hide the tabbar and navigationbar wheni scroll the view and vice versa....Please help me in this
Use one BOOL variable i called it firstTime in .h file
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if(firstTime)
{
[self.navigationController hidesBottomBarWhenPushed];
firstTime=FALSE;
self.navigationController.navigationBar.hidden=TRUE;
}
else
{
[self.navigationController hidesBottomBarWhenPushed];
firstTime=TRUE;
self.navigationController.navigationBar.hidden=FALSE;
}
}
- (BOOL)hidesBottomBarWhenPushed
{
if(firstTime)
{
return TRUE;
}
else
{
return FALSE;
}
}
this will hide your Tabbar and NavigationBar on single tap and viceversa
int DEF_BAR_HEIGHT = 40;
-(void)hideBars:(bool)value
{
// hide navigation bar
[self.navigationController setNavigationBarHidden:value animated:YES];
//hide tabBar
CGRect viewFrame = view.frame;
viewFrame.size.height += value ? DEF_BAR_HEIGHT : -DEF_BAR_HEIGHT; // Change this to the height of the tab bar
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];
view.frame = viewFrame;
[UIView commitAnimations];
}
I'm not sure about DEF_BAR_HEIGHT value. Try 40 or 40 plus navigationBar height.

Scrollview inside containerView won't scroll?

I have a UITableViewController subclass that has a container UIView which has 1 of 2 subviews: the tableview, or a UIScroll depending on whether or not the view is "flipped".
my viewDidLoad() method adds the tableview to the container:
[kContainerView addSubview: self.tableView];
self.view = kContainerView;
and initializes the UIScrollview with an 900x600 image and sets itself as the delegate:
kSBCanvasScrollView = [[UIScrollView alloc] initWithFrame:bounds];
[kSBCanvasScrollView setDelegate: self];
kSBImage = [[UIImageView alloc] initWithImage:img];
[kSBCanvasScrollView addSubview:kSBImage];
[kSBCanvasScrollView setContentSize:[img size]];
[kSBCanvasScrollView setMinimumZoomScale:0.5];
The the front "Table side" of the view works fine. I then flip the view when the user selects a button on the toolbar by doing the following:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0f];
[UIView setAnimationDelegate:self];
if (kSBCanvasIsVisible==NO) {
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:kContainerView cache:YES];
[self.tableView removeFromSuperview];
[kContainerView addSubview:kSBCanvasScrollView];
kSBCanvasIsVisible = YES;
} else {
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:kContainerView cache:YES];
[kSBCanvasScrollView removeFromSuperview];
[kContainerView addSubview:self.tableView];
kSBCanvasIsVisible = NO;
}
[UIView commitAnimations];
It flips just like I want, but the kSBCanvasScrollView does not scroll. The pinch gesture works. Why won't the view scroll? Perhaps it relates to the fact this is a TableViewController?
Is your scrollview 320 x 460? I had to make the scroll view the same , or smaller than the iphone screen for it to work(In IB but not necessarily in the
[kSBCanvasScrollView setContentSize:[img size];).
Did you write:
[kSBCanvasScrollView setScrollEnabled:YES];
PS: I did try this. It worked for me...

For iphone development, how to flip a UIImageView?

I want to flip an imageView (left/right), but I can not find a UIView (or UIImageView) method to do that? any idea?
thanks!
I think the only thing you're looking for is:
UIView's
+ (void)setAnimationTransition:(UIViewAnimationTransition)transition forView:(UIView *)view cache:(BOOL)cache;
and
UIViewAnimationTransitionFlipFromLeft,
UIViewAnimationTransitionFlipFromRight,
These animation transitions can only be used within an animation block. The transition is set on the container view and then the old view is swapped out for the new view, then the animation is committed.
Like:
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:yourContainerView cache:YES];
[yourContainerView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
[UIView commitAnimations];
Put your UIIMageView into a UIView and use this code (from the utility app project sample)
- (void)loadFlipsideViewController {
FlipsideViewController *viewController = [[FlipsideViewController alloc] initWithNibName:#"FlipsideView" bundle:nil];
self.flipsideViewController = viewController;
[viewController release];
// Set up the navigation bar
UINavigationBar *aNavigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
aNavigationBar.barStyle = UIBarStyleBlackOpaque;
self.flipsideNavigationBar = aNavigationBar;
[aNavigationBar release];
UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(toggleView)];
UINavigationItem *navigationItem = [[UINavigationItem alloc] initWithTitle:#"Test123"];
navigationItem.rightBarButtonItem = buttonItem;
[flipsideNavigationBar pushNavigationItem:navigationItem animated:NO];
[navigationItem release];
[buttonItem release];
}
- (IBAction)toggleView {
/*
This method is called when the info or Done button is pressed.
It flips the displayed view from the main view to the flipside view and vice-versa.
*/
if (flipsideViewController == nil) {
[self loadFlipsideViewController];
}
UIView *mainView = mainViewController.view;
UIView *flipsideView = flipsideViewController.view;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:([mainView superview] ? UIViewAnimationTransitionFlipFromRight : UIViewAnimationTransitionFlipFromLeft) forView:self.view cache:YES];
if ([mainView superview] != nil) {
[flipsideViewController viewWillAppear:YES];
[mainViewController viewWillDisappear:YES];
[mainView removeFromSuperview];
[infoButton removeFromSuperview];
[self.view addSubview:flipsideView];
[self.view insertSubview:flipsideNavigationBar aboveSubview:flipsideView];
[mainViewController viewDidDisappear:YES];
[flipsideViewController viewDidAppear:YES];
} else {
[mainViewController viewWillAppear:YES];
[flipsideViewController viewWillDisappear:YES];
[flipsideView removeFromSuperview];
[flipsideNavigationBar removeFromSuperview];
[self.view addSubview:mainView];
[self.view insertSubview:infoButton aboveSubview:mainViewController.view];
[flipsideViewController viewDidDisappear:YES];
[mainViewController viewDidAppear:YES];
}
[UIView commitAnimations];
}
mainView and flipToView are objects of imageViews and containerView is an object of UIView.
Given below are two sample code to curl the imageView and to flip the ImageView from left to Right
- (void)curlAction:(id)sender
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:([mainView superview] ? UIViewAnimationTransitionCurlUp : UIViewAnimationTransitionCurlDown)forView:containerView cache:YES];
if ([flipToView superview])
{
[flipToView removeFromSuperview];
[containerView addSubview:mainView];
}
else
{
[mainView removeFromSuperview];
[containerView addSubview:flipToView];
}
[UIView commitAnimations];
}
and to bring the image from left to right here's the code
- (void)flipAction:(id)sender
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:([mainView superview] ?
UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight)
forView:containerView cache:YES];
if ([flipToView superview])
{
[flipToView removeFromSuperview];
[containerView addSubview:mainView];
}
else
{
[mainView removeFromSuperview];
[containerView addSubview:flipToView];
}
[UIView commitAnimations];
}
Thank &Regards
Another solution is available at my repo but it does'nt involve animation yet! It only manipulates image orientations to provide for some image effects namely flip vertically/horizontally and rotate 90 degrees left/right.