how to perform slide bar navigation so that UITabBar also moves - ios

I have taken a empty application,initially login screen is shown.On entering valid credentials user is navigated to home page where TabBar is shown.On tapping settings icon tab bar should move half way aside.But with my code settings screen is underneath tab bar.How to do so that TabBar also moves.I dont want to use any 3rd part controls.Looking for help.Thanks in advance.Below is my code:
-(void)login{
UIViewController *viewController1 = [[FirstViewController alloc] init];
UINavigationController * firstNavigation = [[UINavigationController alloc]initWithRootViewController:viewController1];
UIViewController *viewController2 = [[SecondViewController alloc] init];
UINavigationController * secondNavigation = [[UINavigationController alloc]initWithRootViewController:viewController2];
tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = #[firstNavigation ,secondNavigation ];
[self.navigationController pushViewController:tabBarController animated:NO];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
_isSideMenuOpen = NO;
UIButton *imageButton1a = [UIButton buttonWithType:UIButtonTypeCustom];
imageButton1a.frame = CGRectMake(0,0,30,30);
[imageButton1a setImage:[UIImage imageNamed:#"setting_icon.png"] forState:UIControlStateNormal];
[imageButton1a addTarget:self action:#selector(goToSettings) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barItem1 = [[UIBarButtonItem alloc] initWithCustomView:imageButton1a];
self.navigationItem.leftBarButtonItem = barItem1;
lbl=[[UILabel alloc]initWithFrame:CGRectMake(10, 100, 150, 30)];
[self.view addSubview:lbl];
lbl.text=#"test label to move";
myView = [[UIView alloc] initWithFrame:self.view.frame];
myView.backgroundColor = [UIColor brownColor];
[myView setFrame:CGRectMake(0, 60, -160, 480)];
[self.view addSubview:myView];
}
-(void)goToSettings
{
if (_isSideMenuOpen)
{
_isSideMenuOpen = NO;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
[myView setFrame:CGRectMake(0, 60, -160, 480)];
[UIView commitAnimations];
// self.view.frame=CGRectMake(0,0,320,self.view.frame.size.height);
}
else
{
_isSideMenuOpen = YES;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[myView setFrame:CGRectMake(0, 60, 160, 480)];
[UIView commitAnimations];
// self.view.frame=CGRectMake(160,0,320,self.view.frame.size.height);
}
}
below is screen shot of o/p I got
but expected o/p is UITabBar should move

Related

ViewController transition by button Touch (no NVController)

I have created a button programmatically and added a selector to it
(touched) which when touchup inside should transist to the next view
controller (LocationVC) with no navigationController between. I have
added in storyboard a second view controller and named its class
"LocationVC2. Somehow nothing happens then a black screen. Any help?
//
// ViewController.h
// NanCom4
//
// Created by Daniel Habshush on 8/30/15.
// Copyright © 2015 Daniel Habshush. All rights reserved.
//
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#property (nonatomic, strong) IBOutlet UIButton *circle1;
#property (nonatomic, strong) IBOutlet UIButton *circle2;
#property (nonatomic, strong) IBOutlet UIButton *circle3;
#property (nonatomic, strong) IBOutlet UIButton *circle4;
#property (nonatomic, strong) IBOutlet UIButton *circle5;
#end
- (void)viewDidLoad {
[super viewDidLoad];
circle1 = [[UIButton alloc] init];
[circle1 setFrame:CGRectMake(128, 247, 100, 100)];
[circle1 setIsAccessibilityElement:YES];
[circle1 addTarget:self action:#selector(pressed3:) forControlEvents:UIControlEventTouchUpInside];
circle1.backgroundColor = [UIColor clearColor];
[circle1 setImage:[UIImage imageNamed:#"Circle6.png"] forState:UIControlStateNormal];
[self.view addSubview:circle1];
circle2 = [[UIButton alloc] init];
[circle2 setFrame:CGRectMake(55, 170, 120, 120)];
[circle2 setIsAccessibilityElement:YES];
[circle2 addTarget:self action:#selector(touch:) forControlEvents:UIControlEventTouchUpInside];
circle2.backgroundColor = [UIColor clearColor];
[circle2 setTitle:#"Orit" forState:UIControlStateNormal];
[circle2 setBackgroundImage: [UIImage imageNamed:#"pie2.png"] forState:UIControlStateNormal];
[self.view addSubview:circle2];
circle3 = [[UIButton alloc] init];
[circle3 setFrame:CGRectMake(55, 300, 120, 120)];
[circle3 setIsAccessibilityElement:YES];
[circle3 setAlpha:0];
circle3.backgroundColor = [UIColor clearColor];
[circle3 setTitle:#"DANI" forState:UIControlStateNormal];
[circle3 setBackgroundImage: [UIImage imageNamed:#"pie3.png"] forState:UIControlStateNormal];
[self.view addSubview:circle3];
circle4 = [[UIButton alloc] init];
[circle4 setFrame:CGRectMake(185, 300, 120, 120)];
[circle4 setIsAccessibilityElement:YES];
[circle4 setAlpha:0];
circle4.backgroundColor = [UIColor clearColor];
[circle4 setTitle:#"DANI" forState:UIControlStateNormal];
[circle4 setBackgroundImage: [UIImage imageNamed:#"pie5.png"] forState:UIControlStateNormal];
[self.view addSubview:circle4];
circle5 = [[UIButton alloc] init];
[circle5 setFrame:CGRectMake(185, 170, 120, 120)];
[circle5 setIsAccessibilityElement:YES];
[circle5 setAlpha:0];
circle5.backgroundColor = [UIColor clearColor];
[circle5 setTitle:#"DANI" forState:UIControlStateNormal];
[circle5 setBackgroundImage: [UIImage imageNamed:#"pie4.png"] forState:UIControlStateNormal];
[self.view addSubview:circle5];
}
- (void)pressed3:(UIButton*)sender {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationDelay:0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn ];
self.circle1.alpha = 0.2;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0];
[UIView setAnimationDelay:0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn ];
self.circle2.alpha = 1;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.25];
[UIView setAnimationDelay:0.25];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn ];
self.circle3.alpha = 1;
[UIView commitAnimations];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.25];
[UIView setAnimationDelay:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn ];
self.circle4.alpha = 1;
[UIView commitAnimations];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.25];
[UIView setAnimationDelay:0.75];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn ];
self.circle5.alpha = 1;
[UIView commitAnimations];
}
- (void)touch:(id)sender
{
LocationVC *newVC = [LocationVC new];
[self presentViewController:newVC animated:YES completion:nil];
}
#end

Show a UIViewController as Alert View in iOS

I'm trying to create a custom Alert View similar to this
I want to use a View Controller as the alert because the 'X' button on the top left corner must be there, and neither a regular UIAlertController or any pod I found can help me with that.
How can I achieve this?
Thank you.
For showing viewController as UIAlertView try this
SecondViewController *secondViewController = [[UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:#"SecondViewController"];
secondViewController.view.frame = self.view.frame;
[self.view addSubview:secondViewController.view];
secondViewController.view.transform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
secondViewController.view.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished){
}];
try this..
#interface alertViewController ()
{
UILabel *labelTitle;
UIView *viewToShow,*viewAlert;
}
#end
#implementation alertViewController
- (void)viewDidLoad
{
[super viewDidLoad];
viewToShow = [[UIView alloc]initWithFrame:CGRectMake(0,0, 165*2, 400)];
[viewToShow setBackgroundColor:[UIColor whiteColor]];
[viewToShow setOpaque:NO];
[self.navigationController.view addSubview:viewToShow];
labelTitle = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 165*2, 30)];
[[labelTitle layer] setCornerRadius:14];
labelTitle.text=#"TITLE";
[labelTitle setTextAlignment:NSTextAlignmentCenter];
[viewToShow addSubview:labelTitle];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:#selector(cancelButtonAction:)
forControlEvents:UIControlEventTouchUpInside];
[button setTitle:#"X" forState:UIControlStateNormal];
[button.titleLabel setFont:[UIFont fontWithName:#"helvetica-neue" size:20]];
button.frame = CGRectMake(5,5,30, 40.0);
[viewToShow addSubview:button];
UITextView *textView=[[UITextView alloc]initWithFrame:CGRectMake(10, 60,viewToShow.frame.size.width-20, 250)];
[textView setBackgroundColor:[UIColor lightGrayColor]];
[viewToShow addSubview:textView];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button1 addTarget:self
action:#selector(cancelButtonAction:)
forControlEvents:UIControlEventTouchUpInside];
[button1 setTitle:#"Continue" forState:UIControlStateNormal];
button1.frame = CGRectMake((viewToShow.frame.size.width/2)-40,viewToShow.frame.size.height-40,80,40);
[viewToShow addSubview:button1];
[[viewToShow layer] setCornerRadius:14];
CGPoint centerForCustomExportView;
if (UIDeviceOrientationIsLandscape((UIDeviceOrientation)[[UIApplication sharedApplication] statusBarOrientation]))
{
centerForCustomExportView = CGPointMake(([[UIScreen mainScreen]bounds].size.height>[[UIScreen mainScreen]bounds].size.width?[[UIScreen mainScreen]bounds].size.height:[[UIScreen mainScreen]bounds].size.width)/2, (([[UIScreen mainScreen]bounds].size.height>[[UIScreen mainScreen]bounds].size.width?[[UIScreen mainScreen]bounds].size.width:[[UIScreen mainScreen]bounds].size.height)/2));
}
else
{
centerForCustomExportView = CGPointMake([[UIScreen mainScreen]bounds].size.width/2, ([[UIScreen mainScreen]bounds].size.height-self.navigationController.navigationBar.frame.size.height)/2);
}
viewToShow.center = centerForCustomExportView;
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(deviceRotated:)name:UIDeviceOrientationDidChangeNotification object:nil];
}
try this.....
- (void)show
{
NSLog(#"show");
isShown = YES;
self.transform = CGAffineTransformMakeScale(0.1, 0.1);
self.alpha = 0;
[UIView beginAnimations:#"showAlert" context:nil];
[UIView setAnimationDelegate:self];
self.transform = CGAffineTransformMakeScale(1.1, 1.1);
self.alpha = 1;
[UIView commitAnimations];
}

How to fit image in UITextView and Tap to get larger

I have created a Table-view in main ViewController once i touch the row it will take to the next view controller(DetailViewController) where it display the image and name of dish.And once i tap the image it should get larger but it is not getting bigger .The below code is which i have tried in DetailViewController.
DetailViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
imageView=[[UIImageView alloc] initWithFrame:CGRectMake(10, 10,100, 100)];
CGRect textViewFrame = CGRectMake(10, 10, 300, 400);
textView = [[UITextView alloc] initWithFrame:textViewFrame];
textView.returnKeyType = UIReturnKeyDone;
textView.backgroundColor=[UIColor whiteColor];
textView.editable=NO;
textView.delegate = self;
[self.view addSubview:textView];
[textView addSubview:imageView];
textView.alpha = 0.9;
textView.font = [UIFont systemFontOfSize:15];
if(mrowno==0)
{
imageView.image=[UIImage imageNamed:#"Dosa.jpg"];
textView.text = #"\n\n\n\n\n\n\n\nDOSA\nDosa, ";
imageButton = [[UIButton alloc]init];
[imageButton setFrame:CGRectMake(0, 0, 100, 100)];
[imageButton addTarget:self action:#selector(imageTapped:) forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:imageButton];
}
Here is the method to make image larger
-(void)imageTapped:(UIButton*)in_sender
{
[UIView transitionWithView:in_sender.superview duration:0.8f options:UIViewAnimationOptionCurveLinear animations:^
{
[in_sender.superview setFrame:CGRectMake(0, 0, 300, 500)];
}
completion:^(BOOL finished)
{
}];
}
You can increase and decrease the size of image by pinch in and pinch out,If it required
-(void)viewDidLoad
{
UIPinchGestureRecognizer* pinch=[[UIPinchGestureRecognizer alloc] initWithTarget:self action:#selector(pinching:)];
[self.imageView addGestureRecognizer:pinch];
}
-(void)pinching:(UIGestureRecognizer*) recognizer
{
UIPinchGestureRecognizer* pinch=(UIPinchGestureRecognizer*) recognizer;
self.imageView.transform=CGAffineTransformScale(self.imageView.transform, pinch.scale, pinch.scale);
pinch.scale=1;
NSLog(#"pinching");
}
You do not want to use transitionWithView. Instead, you want to use + animateWithDuration: delay:options:animations:completion: (or any of its shorter variants...)
[UIView animateWithDuration:0.3f delay:0.0f options:UIViewAnimationOptionCurveEaseInOut animations:^{
viewYouWantToAnimate.frame = CGRectMake(..., ..., ..., ...);
} completion:^{
//Add completion code here, or pass nil if you don't have anything to do.
}];
Edit: In case you were wondering what transitionWithView was used for... the AppleDocs have a great example of it adding animations for remove/addSubview methods (not frame modifications):
[UIView transitionWithView:containerView
duration:0.2
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
[fromView removeFromSuperview];
[containerView addSubview:toView];
} completion:NULL];

Info lightbutton animation

I am having trouble in showing infobutton to navigate to information page/view.
I have written this code.
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
UIBarButtonItem *infoButtonItem = [[UIBarButtonItem alloc] initWithCustomView:infoButton];
toolBar.items = [NSArray arrayWithObjects:infoButtonItem, nil];
I got infolight button but i do not now know how to do animate & navigation action method in to flip to info page.
I also want infobutton to stay at center, currently it is at left corner.
This will create ur info button in center.
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
UIBarButtonItem *infoButtonItem = [[UIBarButtonItem alloc] initWithCustomView:infoButton];
[infoButton addTarget:self action:#selector(goToRechercherView) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *flexibleLeft = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
toolbar.items = [NSArray arrayWithObjects:flexibleLeft,infoButtonItem,flexibleLeft, nil];
This is for swipe animation. add your view inside.
-(void)goToRechercherView{
[UIView beginAnimations:#"flipview" context:nil];
[UIView setAnimationDuration:2];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:self.view cache:YES];
[UIView commitAnimations];
}
There are two ways to do this...
First one is......
newView setFrame:CGRectMake( 0.0f, 480.0f, 320.0f, 480.0f)]; //notice this is OFF screen!
[UIView beginAnimations:#"animateView" context:nil];
[UIView setAnimationDuration:0.4];
[newView setFrame:CGRectMake( 0.0f, 0.0f, 320.0f, 480.0f)]; //notice this is ON screen!
[UIView commitAnimations];
Second option is to use built in animations as flip and curl:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
forView:newView
cache:YES];
[self.navigationController.view addSubview:settingsView.view];
[UIView commitAnimations];

Bring up the UIDatePicker in a subview doesn't animate properly, but bringing it down does

I have made a remide button that bring up this subview, everything works but the animation looks really bad. Here is the code to bring it up:
int height = 255;
//create new view
self.NewView = [[UIView alloc] initWithFrame:CGRectMake(0, 200, 320, height)];
self.NewView.backgroundColor = [UIColor colorWithWhite:1 alpha:1];
//add toolbar
UIToolbar * toolbar = [[UIToolbar alloc] initWithFrame: CGRectMake(0, 0, 320, 40)];
toolbar.barStyle = UIBarStyleBlack;
//add button
UIBarButtonItem *infoButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Done" style:UIBarButtonItemStyleDone target:nil action:#selector(dismissCustom:)];
toolbar.items = [NSArray arrayWithObjects:infoButtonItem, nil];
//add date picker
self.datePicker = [[UIDatePicker alloc] init];
self.datePicker.datePickerMode = UIDatePickerModeDateAndTime ;
self.datePicker.hidden = NO;
self.datePicker.date = [NSDate date];
self.datePicker.frame = CGRectMake(0, 40, 320, 250);
[self.datePicker addTarget:self action:nil forControlEvents:UIControlEventValueChanged];
[self.NewView addSubview:self.datePicker];
//add popup view
[self.NewView addSubview:toolbar];
__block CGRect temp = self.NewView.frame;
temp.origin.y = CGRectGetMaxY(self.view.bounds);
[UIView animateWithDuration:0.5
animations:^{temp.origin.y -= height, self.NewView.frame = temp;}
completion:^(BOOL finished) {[self.view addSubview:self.NewView];}];
Here is the code for the exiting of the subview which works well:
int height = 0;
__block CGRect temp = self.NewView.frame;
temp.origin.y = CGRectGetMaxY(self.view.bounds);
[UIView animateWithDuration:0.5 animations:^{temp.origin.y -= height, self.NewView.frame = temp;} completion:^(BOOL finished) {
[self.NewView removeFromSuperview];}];
Anyone know whats going wrong?
Thanks!
Add NewView to self.view before the animation
CGFloat height = 255.0;
// create new view
self.NewView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.view.bounds), 320, height)];
// init and add toolbar, button and pickerView as in your code
// ...
// add popup view
[self.view addSubview:self.NewView];
CGRect newViewFrame = self.NewView.frame;
newViewFrame.origin.y -= newViewFrame.size.height;
[UIView animateWithDuration:0.5 animations:^{
self.NewView.frame = newViewFrame;
} completion:nil];

Resources