I want to hide my toolbar if I click on a button, but it doesn't seem to work. I can hide the toolbar with an animation but I can't let it show up again. Thanks!
- (IBAction)hideTheToolBar{
//[toolBar setHidden:YES];
if (toolbar.hidden == NO)
{
[UIView animateWithDuration:0.25 delay:0.0
options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction
animations:^(void)
{
toolbar.alpha = 0.0f;
}
completion:^(BOOL finished)
{
toolbar.hidden = YES;
}
];
}
if (toolbar.hidden == YES) {
toolbar.hidden = NO;
}
}
i think u are missing a statement in the second if loop try:
if (toolbar.hidden == YES) {
toolbar.hidden = NO;
toolbar.alpha = 1.0f ;
}
Related
Using Obj-c to animate alpha continously but when I try to nil our and remove the subview it sticks around and won't delete or stop animating?
-(void)flashFingerPrint{
[UIView animateKeyframesWithDuration:1 delay:0 options:UIViewAnimationOptionRepeat|UIViewAnimationOptionAutoreverse|UIViewAnimationCurveEaseInOut animations:^{
self.purpleFingerPrint.alpha = 0;
} completion:^(BOOL finished) {
nil;
}];
}
-(void)hidePurpleHelper {
if(nil != self.purpleFingerPrint && nil != self.purpleFingerPrint) {
// add it to the screen with animation
[UIView animateWithDuration:0.5 delay:0.2 options:(UIViewAnimationCurveEaseOut) animations:^{
self.purpleHelperView.alpha = 0;
self.purpleFingerPrint.alpha = 0;
self.purpleFingerPrint = nil;
[self.view willRemoveSubview:self.purpleFingerPrint];
} completion:^(BOOL finished) {
// nothing
self.purpleHelperView = nil;
self.purpleFingerPrint = nil;
[self.view willRemoveSubview:self.purpleFingerPrint];
}];
}
}
I call the hide function but the fingerprint still shows on screen and still flashing?
You need
[self.purpleFingerPrint removeFromSuperview];
I have a UIButton at the position x=0.0. Now when I am pressing that button the button is shifting and goes to a position at x=131.0. Now when I am pressing that again it should come back to x=0.0 position. But its not coming. It is staying at the position x=131.0.
This is the code I have written
- (IBAction)showMenuViewButton:(id)sender {
_horizontalConstraintsOfColorViewToMainView.constant = 0.0;
_buttonOfColorViewHoriozontalLeadingConstraints.constant = 131.0;
counter=counter+1;
if (counter%2 !=0) {
[UIView animateWithDuration:0.4
animations:^
{
_menuView.hidden = NO;
_menuView.frame = CGRectMake(0.0, _menuView.frame.origin.y, _menuView.frame.size.width, _menuView.frame.size.height);
_showMenuViewButton.frame = CGRectMake(_showMenuViewButton.frame.origin.x+_menuView.frame.size.width+_showMenuViewButton.frame.size.width,_showMenuViewButton.frame.origin.y, _showMenuViewButton.frame.size.width, _showMenuViewButton.frame.size.width);
}];
}
else{
[UIView animateWithDuration:0.4
animations:^
{
_menuView.hidden = NO;
_menuView.frame = CGRectMake(-102.0, _menuView.frame.origin.y, _menuView.frame.size.width, _menuView.frame.size.height);
_showMenuViewButton.frame = CGRectMake(0.0,_showMenuViewButton.frame.origin.y, _showMenuViewButton.frame.size.width, _showMenuViewButton.frame.size.width);
}];
}
}
Here I have changed button frame for animation not change any contarint
- (IBAction)clickButton:(id)sender {
if (!isChangedPlace) {
isChangedPlace = true;
[UIView animateWithDuration:1.0
animations:^{
btn.frame = CGRectMake(btn.frame.origin.x, btn.frame.origin.y+100, btn.frame.size.width, btn.frame.size[self.height);view layoutIfNeeded];
}];
}
else
{
isChangedPlace = false;
[UIView animateWithDuration:1.0
animations:^{
btn.frame = CGRectMake(btn.frame.origin.x, btn.frame.origin.y-100, btn.frame.size[self.width,view btn.frame.size.height);layoutIfNeeded];
}];
}
}
Here I have change buttons Y constraint for animating it
I have set Y constraint using IBOutlet and change that value as follow.
- (IBAction)clickButton:(id)sender {
if (!isChangedPlace) {
isChangedPlace = true;
buttonYPointConstraint.constant += 50;
}
else
{
isChangedPlace = false;
buttonYPointConstraint.constant -= 50;
}
[UIView animateWithDuration:1.0 animations:^{
[self.view layoutIfNeeded];
}];
}
I hope it will help you!
Hello and thank you in advance...
I am moving views frame location in animation blocks. After I move views, I am tapping a textView to allow for editing/input. When the textView is tapped, the views I moved previously pop back to their original (unmoved) frame locations.
I'm not sure what I am doing incorrectly here.
THIS IS HOW I SETUP THE DIFFERENT FRAME POSITIONS TO ANIMATE TO
//Books active and rest position will effect other elements (paper and paperTextView)
self.bookRestPosition = CGRectMake((self.view.frame.size.width * 0.10), (self.view.frame.size.height * 0.4), self.view.frame.size.width, self.view.frame.size.height);
self.bookActivePosition = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y +100, self.view.frame.size.width, self.view.frame.size.height);
self.bookOpenPosition = CGRectMake(self.bookActivePosition.origin.x, self.bookActivePosition.origin.y, 20, self.bookActivePosition.size.height);
self.quillRestPosition = self.quill.frame;
self.quillActivePosition = CGRectMake(self.quill.frame.origin.x, self.view.frame.origin.y -200, self.quill.frame.size.width, self.quill.frame.size.height);
self.woodTableRestPosition = self.view.frame;
self.woodTableActivePosition = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y -200, self.view.frame.size.width, self.view.frame.size.height +200);
self.paperRestPosition = self.bookRestPosition;
self.paperActivePosition = CGRectMake(self.bookOpenPosition.size.width, self.bookActivePosition.origin.y, self.bookActivePosition.size.width, self.bookActivePosition.size.height);
self.paperTextViewRestPosition = self.bookRestPosition;
self.paperTextViewActivePosition = self.paperActivePosition;
self.paperTextView.editable = NO;
self.paper.alpha = 0.0;
self.paperTextView.alpha = 0.0;
self.paper.frame = self.bookRestPosition;
self.paperTextView.frame = self.bookRestPosition;
THIS IS HOW I ANIMATE THEM
- (IBAction)onBookTapped:(UITapGestureRecognizer *)sender {
if (self.logCover.frame.origin.x == self.bookRestPosition.origin.x) {
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
[self activateLogAndViewsAssociated];
} completion:^(BOOL finished) {
NSLog(#"Book Slid up!");
}];
}
else if (self.logCover.frame.origin.x == 0){
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
[self everythingAtRestPosition];
} completion:^(BOOL finished) {
NSLog(#"Book Slid Down!");
}];
}
}
- (IBAction)swipeBookLeft:(UISwipeGestureRecognizer *)sender {
//if (self.logCoverImage.frame.origin.x == 0) {
self.paper.alpha = 1.0;
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
[self.logCover setFrame:self.bookOpenPosition];
self.editButton.alpha = 1.0;
self.editButton.enabled = YES;
} completion:^(BOOL finished) {
NSLog(#"Book Has Opened!");
//This must be here. The paperTextView is what the swipe right gesture is attached to
self.paperTextView.alpha = 1.0;
// self.logCoverImage.alpha = 0.0;
// self.quill.alpha = 0.0;
}];
//}
}
- (IBAction)onPaperSwipeRight:(UISwipeGestureRecognizer *)sender {
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
[self.logCover setFrame:self.bookActivePosition];
self.editButton.alpha = 0.0;
self.editButton.enabled = NO;
} completion:^(BOOL finished) {
NSLog(#"Book Has Closed!");
//self.paper.alpha = 0.0;
// [NSUserDefaults *log = [NSUserDefaults standardUserDefaults];
// [log setObject:self.paperTextView forKey:#"textLog"];
}];
}
- (IBAction)onBookSwipeDown:(UISwipeGestureRecognizer *)sender {
if (self.logCover.frame.origin.x == 0) {
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
[self everythingAtRestPosition];
} completion:^(BOOL finished) {
NSLog(#"Book Slid Down!");
}];
}
}
- (IBAction)onBookSwipeUp:(UISwipeGestureRecognizer *)sender {
if (self.logCover.frame.origin.x == self.bookRestPosition.origin.x) {
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
[self activateLogAndViewsAssociated];
} completion:^(BOOL finished) {
NSLog(#"Book Slid up!");
}];
}
}
- (void)animateAtStartup
{
self.logCover.frame = CGRectMake(self.view.frame.size.width, self.view.frame.size.height, self.bookRestPosition.size.width, self.bookRestPosition.size.height);
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
[self.logCover setFrame:self.bookRestPosition];
} completion:^(BOOL finished) {
NSLog(#"Book Slid Down!");
}];
}
AND THIS IS WHAT HAPPENS WHEN THE EDIT BUTTON IS PRESSED
- (IBAction)onEditButtonPressed:(id)sender
{
self.paperTextView.editable = YES;
[self.paperTextView becomeFirstResponder];
}
I have a tableview with a hidden property. I want to unhide it with animation so that it could slide from bottom to top? Any suggestions please.
-(IBAction) hideTable : (id) sender;
{
if(self.tb.hidden==true)
{
self.tb.alpha=1;
[self.tb setHidden:NO];
}
else{
[self.tb setHidden:YES];
}
}
-(IBAction) hideTable : (id) sender{
if (self.sessionView.hidden == YES) {
// Currently NOT Visible. Show it now
// First unhide it
yourTableView.hidden = NO;
[UIView animateWithDuration:0.5f
animations:^{
// Get the Existing table View frame
CGRect hiddenFrame = yourTableView.frame;
// Reset it to 0 or your own value
hiddenFrame.origin.y = 0;
// Set the new frame
yourTableView.frame = hiddenFrame;
} completion:^(BOOL finished) {
NSLog(#"Shown");
}];
}
else{
// Currently Visible. Hide it Now
[UIView animateWithDuration:0.5f
animations:^{
// Get the Existing table View frame
CGRect hiddenFrame = yourTableView.frame;
// Under the superview height
hiddenFrame.origin.y = yourTableView.superview.frame.size.height;
// Set the new frame
yourTableView.frame = hiddenFrame;
} completion:^(BOOL finished) {
yourTableView.hidden = YES;
NSLog(#"Hidden");
}];
}
}
try this
CGRect frame = self.tb.frame;
if (self.tb.hidden) {
CGRect temp_frame = frame;
frame.size.height = 1;
self.tb.frame = temp_frame;
self.tb.hidden = NO;
[UIView animateWithDuration:0.3
animations:^{
self.tb.frame = frame;
} completion:^(BOOL finished) {
}];
}
else
{
[UIView animateWithDuration:0.3
animations:^{
CGRect temp_frame = frame;
frame.size.height = 1;
self.tb.frame = temp_frame;
} completion:^(BOOL finished) {
self.tb.hidden = YES;
}];
}
try this
-(IBAction) hideTable : (id) sender;
{
if(self.tb.hidden==true)
{
self.tb.alpha=1;
[self.tb setHidden:NO];
[UIView animateWithDuration:.25
animations:^{
self.tb.frame = CGRectMake(0,50,320,400); // your req frame
}
];
}
else
{
[UIView animateWithDuration:0.35
animations:^{
self.tb.frame = CGRectMake(0, self.view.frame.size.height+10, 320,400); // y point of yor tableview is more than view bounds so it goes down
}
completion:^(BOOL finished){
[self.tb setHidden:YES];
}
];
}
}
You can use the below methods:
1. (void)showDropDownTable:- To show tableview with top to bottom animation.
2. (void)hideDropdownTable:- To hide tableview with bottom to top animation.
- (IBAction)btnDropDownClicked:(id)sender
{
if (checkShowHideTableView == TRUE)
{
[self hideTableView];
}
if (self.tblDropDown.hidden)
{
[self showDropDownTable];
}
else
{
[self hideDropdownTable];
}
}
- (void)showDropDownTable
{
[UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationCurveEaseOut animations: ^{
_tblDropDown.frame = CGRectMake(self.tblDropDown.frame.origin.x, self.tblDropDown.frame.origin.y, self.tblDropDown.frame.size.width, kDropdownTableHeight);
self.tblDropDown.hidden = FALSE;
} completion: ^(BOOL finished) {
}];
}
- (void)hideDropdownTable
{
[UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationCurveEaseOut animations: ^{
_tblDropDown.frame = CGRectMake(self.tblDropDown.frame.origin.x, self.tblDropDown.frame.origin.y, self.tblDropDown.frame.size.width, 0);
} completion: ^(BOOL finished) {
self.tblDropDown.hidden = TRUE;
}];
}
Hope this can help you.
Try the following
[self.tb beginUpdates];
[UIView animateWithDuration:0.5
delay:0.1
options:(UIViewAnimationCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction)
animations:^{
if(self.tb.isHidden)
{
self.tb.alpha=1;
[self.tb setHidden:NO];
}
else
{
self.tb.alpha=0;
[self.tb setHidden:YES];
}
}
completion:^(BOOL finished) {
}];
[self.tb endUpdates];
I have the following if statement,
if (CGRectIntersectsRect(car.frame, car2.frame) && (upMovement = -1 ) && (car2.hidden == NO)){
[self bounce];
[self carexplode];
if (car2used == NO) {
addedScore = 1;
car2Used = YES;
}
car2.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"car2flames.png"], nil];
[car2 setAnimationRepeatCount:0];
car2.animationDuration = 20;
[car2 startAnimating];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:4];
[iceblock6 setAlpha:0];
[UIView commitAnimations];
car2.hidden = YES;
Essentially, I want it to execute the top part of the method if one car crashes into it, then using UIView animations ^^, I want it to fade out, then be hidden, so that I can set hidden to no again when it reenters the view (after it exits the screen it reloads to the top of the screen). But with this, it just automatically is hidden, without the 4 second fade out animation. How can I fix this? I've tried putting car2.hidden in an if statement, but I don't know what to put in the condition because UIView isn't really bools or integers and all that. Anyone have any advice?
[UIView animateWithDuration:1.0 delay:0.0 options:(UIViewAnimationOptions) animations:^{
//place your animation here
[iceblock6 setAlpha:0];
} completion:^(BOOL finished) {
//called when animation did finish. do what you want
car2.hidden = YES;
}];
Other way:
{
...
if (CGRectIntersectsRect(car.frame, car2.frame) && (upMovement = -1 ) && (car2.hidden == NO)){
[self bounce];
[self carexplode];
if (car2used == NO) {
addedScore = 1;
car2Used = YES;
}
car2.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"car2flames.png"], nil];
[car2 setAnimationRepeatCount:0];
car2.animationDuration = 20;
[car2 startAnimating];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:4.0];
[iceblock6 setAlpha:0];
[UIView commitAnimations];
[self performSelector:#selector(hideCar2) withObject:self afterDelay:4.0];
}
-(void)hideCar2
{
car2.hidden = YES;
}