Hello Im having trouble with my image view. i have a login view controller and i have a UIButton when clicked an image view animates across the view controller which is this:
- (IBAction)alreadyUser:(id)sender {
[_usnernameField resignFirstResponder];
[_passwordField resignFirstResponder];
[UIView animateWithDuration:0.3 animations:^{_loginOverlayView.frame = self.view.frame;
}];
}
but i can’t figure out how to undo this action i tried [_loginOverlayView setHidden:YES];
but then it states hidden when i try to come back to it
Appear:
[_loginOverlayView setHidden:NO];
Disappear:
[_loginOverlayView setHidden:YES];
you can put before or after the animation to hide or show the loginOverlayView.
Related
I have one mainview UIViewController. in that view put one UIView name loginview with small size(self.loginview.frame = CGRectMake(4,166,306,153);
In mainview uiviewcontroller i put one button if i click that button loginview want to display like popup... how can i achieve this help me here code.
- (IBAction)Regbtn_click:(id)sender
{
//in this place i want to write the code for login view want come like popup.. help me..
loginview.hidden=false
}
Instead of setting hidden property of your loginview, set its alpha to 0.0 and you can use this animation
-(IBAction)Regbtn_click:(id)sender {
//[self.view addSubview:self.loginView]; if your loginview is not added to view, if it is, ignore this line
[UIView animateWithDuration:0.5 animations:^{
self.loginView.alpha = 1.0; //to display loginview
} completion:^(BOOL finished) {
}];
}
You can animate the view with two animations:
1) scaling
2) fading
View Controller
->Button (Viewcontroller Child)
->LoginWrapperView (Viewcontroller Child)
->black-transparent View (LoginWrapperView Child)
->login View (LoginWrapperView Child)
Add black semi-transparent view (with opacity of 0.2 i think) on screen and above that place your loginView and set its opacity to 0.
[LoginWrapperView SetHidden:YES];
[loginView SetAlpha:0];
[loginView SetFrame:CGRectMake(0,0,0,0)];
Now when you click on the button,
[LoginWrapperView SetHidden:NO];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.2];
[UIView setAnimationDelegate:self];
//position on screen
[loginView SetAlpha:1];
[loginView SetFrame:<your CGRect goes here>];
[UIView setAnimationDidStopSelector:#selector(finishAnimation:finished:context:)];
//animate off screen
[UIView commitAnimations];
Then handle Tap Getsture on semi-transparent view to close or hide the same by reversing the same animation with different values.
You can push your view modally or use a nice library like MZFormSheetController that do just that.
Here's how it looks like
It is simple just present your view. You could also make the background transparent and many other customization.
YourPopupViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"PopupView"];
-(IBAction)buttonClick{
// present form sheet with view controller
[self mz_presentFormSheetController:vc animated:YES completionHandler:^(MZFormSheetController *formSheetController) {
//do your login stuff
}];
}
When I change my UIBarButtonItems they change abruptly, unlike the default which gives a nice but speedy fade animation. You can see this when segueing between view controllers, for instance, the back button will fade in and out. How can I simulate the same effect?
Update - Based on this answer - https://stackoverflow.com/a/10939684/2649021
It looks like you would have to do something like this to make the button itself fade out.
[self.navigationItem setRightBarButtonItem:nil animated:YES];
And do something like this to make it fade in
[self.navigationItem setRightBarButtonItem:myButton animated:YES];
Otherwise if you want more control over animation properties you would have to create a custom view I believe.
EDIT: I just confirmed that you can fade a UIBarButtonItem custom view using this.
As a test I created a simple project and dropped a UIBarButtonItem onto the navigation bar. I created an outlet to the view controller. In viewDidLoad on the view controller I setup a custom view
-(void)viewDidLoad{
[super viewDidLoad];
UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(0,0,40,40)];
lbl.text = #"test";
UIView *customView = [[UIView alloc]initWithFrame:CGRectMake(0,0,40,40)];
[customView addSubview:lbl];
self.barButtonItem.customView = customView;
}
As a test in viewDidAppear I animated it
-(void)viewDidAppear:(BOOL)animated
{
[UIView animateWithDuration:3.0
delay:3.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
self.barButtonItem.customView.alpha = 0;
}
completion:^(BOOL finished) {
NSLog(#"animation complete");
}];
EDIT: Here's a link to Apples Documentation for a full explanation of UIView animations.
https://developer.apple.com/library/ios/documentation/windowsviews/conceptual/viewpg_iphoneos/animatingviews/animatingviews.html
You might have to create a custom bar button item using a view or an image, and then animate the properties of the view as digitalHound shows.
I have a search bar embedded above a tableview which is visible as soon as the view is opened i want it to be hidden when the page loads and on click of the search button (Bottom left corner) i want the searchbar to get animated from top. I have read that this can be done using UIScrollview, but none of the tutorials have been able to help me.
For
1)I want it to be hidden when the page loads and on click of the search button
In your search button clicked...
if(self.searchBar.isHidden)
{
[sender setSelected:YES];
self.searchBar.hidden=NO;
[self resetFrame:tableView toFrame:CGRectMake(tableView.frame.origin.x, tableView.frame.origin.y+44, tableView.frame.size.width, tableView.frame.size.height) withDelay:0.5];
}
else if(!self.searchBar.isHidden)
{
[sender setSelected:NO];
self.searchBar.hidden=YES;
[self resetFrame:tableView toFrame:CGRectMake(tableView.frame.origin.x, tableView.frame.origin.y-44, tableView.frame.size.width, tableView.frame.size.height) withDelay:0.5];
[self.searchBar resignFirstResponder];
}
-(void)resetFrame:(UIView *)view toFrame:(CGRect )frame withDelay:(float)delay
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:delay];
[view setFrame:frame];
[UIView commitAnimations];
}
}
Just add the above when you click search button or if want it to be hidden when page shows add it in the viewWillAppear method
2)i want the searchbar to get animated from top.
Add the searchbar to the view by making its y axis below 0 example -100 and once page loads set its actual frame use resetFrame method to bring your search bar from top
my app consists of a table view controller and a view controller. when i press a cell in the table view, the toolbar at that view slips with animation down outside the screen and when i'm in the view controller and press back, the toolbar bar slips upwards to it's original position. My problem is, i figured out a bug that when i'm in the view controller and press the home button to exit the app and then come back. the app resumes where i left but when i go back to the table view, the toolbar shifts upwards beyond it's original position. the sliding of the toolbar works fine when i'm in the app before exiting. so there's like something is being called to reset the toolbar to it's origin and thus adding the additional y-axis point to shift more upwards. does anybody know what are those methods?
Code:
i have this in the viewWillAppear method of the view controller:
[UIView animateWithDuration:0.7 animations:^{
self.navigationController.toolbar.center = CGPointMake(self.navigationController.toolbar.center.x, self.navigationController.toolbar.center.y + self.navigationController.toolbar.frame.size.height);
} completion:^(BOOL finished){
self.navigationController.toolbar.hidden = YES;
}];
and in the same view when it needs to disappear i added this in the viewWillDisappear:
[[self.navigationController toolbar] setHidden:NO];
[UIView animateWithDuration:1 animations:^{
self.navigationController.toolbar.center = CGPointMake(self.navigationController.toolbar.center.x, self.navigationController.toolbar.center.y - self.navigationController.toolbar.frame.size.height);
} completion:^(BOOL finished){
}];
i tried this as another way to animate the hiding of the toolbar but there is no animation:
- (void) viewWillAppear:(BOOL)animated
{
[self.picker setHidden:YES];
[self.navigationController setToolbarHidden:YES animated:YES];
}
- (void) viewWillDisappear:(BOOL)animated
{
[self.navigationController setToolbarHidden:NO animated:YES];
[self.course setValue:self.nameTextField.text forKey:#"courseName"];
[self.course setValue:[NSNumber numberWithInt:[self.creditsTextfield.text integerValue]] forKey:#"courseCredits"];
[self.course setValue:[NSNumber numberWithInt:[self.chaptersTextfield.text integerValue]] forKey:#"courseChapters"];
[self.course setValue:self.gradeTextfield.text forKey:#"courseGrade"];
}
For one thing, you should use frame instead of center, but replace the viewWillDisappear animation line with this:
self.navigationController.toolbar.frame = CGRectMake(0,0,self.navigationController.toolbar.frame.size.width, self.navigationController.toolbar.frame.size.height);
and tell me what happens...
That should fix your problem.
Since you are using the toolbar belonging to a UINavigationController (and not a standalone UIToolbar instantiated and added to a UIView by your own controller), it's better to use the methods that UINavigationController exposes, because you don't know how it manages and move its UIToolbar.
Try to put just this in viewWillAppear:, instead of the entire animation block
[self.navigationController setToolbarHidden:NO animated:YES];
and this in viewWillDisappear:
[self.navigationController setToolbarHidden:YES animated:YES];
i fixed it! i aded the following lines of code in viewWillDisappear:
self.navigationController.toolbar.center = CGPointMake(self.navigationController.toolbar.center.x, 458);
self.navigationController.toolbar.center = CGPointMake(self.navigationController.toolbar.center.x, self.navigationController.toolbar.center.y + self.navigationController.toolbar.frame.size.height);
since the problem seems that when the app goes background then foreground the toolbar resets to it's original position and thus after navigating back to the table view the toolbar is shifted beyond it's original position. therefore the first line i added resets the toolbar to it's original position while still hidden then shift it down. after that the block of animation is done. i did this so that the animation works on the following cases:
1. the user enters the detail view from the table view then goes back to the tableview without exiting the app.
2. the user enters the detail view from the tableview then exits the app and then resume the app and goes back to the table view.
Do any of you know how I could possibly add an animation that is triggered when a UIButton is pressed, and the UIButton turns aand enlarges at the same time, and on the other side I can show another view? A bit like in dashboard on a Mac, with the info button on the widgets...
You can use transitions:
[UIView transitionWithView:containerView duration:1 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
buttonView.hidden = YES;
otherView1.hidden = NO;
otherView2.hidden = NO;
otherViewEtc.hidden = NO;
} completion:nil];
You would then have a containerView which contains the flip button and the alternate view hidden, and in the transition, you can hide the first view and show the alternate view...