Removing and nil out object used in animation won't nil - ios

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];

Related

Button's frame is not changing

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!

Animations in TableView in Ios

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];

How to hide an item after fading it out (Objective-C)

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;
}

ios removeAllAnimations not working

I have an forever animation, but I want to stop it at some point I tried removeAllAnimations but it did not work.
Here is my code.
[self.backgroundImageView.layer removeAllAnimations];
-(void)animateToLeft{
if(isInCenter){
[UIView animateWithDuration:10.0f animations:^{
backgroundImageView.frame = CGRectMake(kLeftX, 0, kBackgroundWidth, kBackgroundHeight);
}completion:^(BOOL finished) {
[self animateToRight];
}];
isInCenter = NO;
}
else{
[UIView animateWithDuration:20.0f animations:^{
backgroundImageView.frame = CGRectMake(kLeftX, 0, kBackgroundWidth, kBackgroundHeight);
}completion:^(BOOL finished) {
[self animateToRight];
}];
}
}
-(void)animateToRight{
[UIView animateWithDuration:20.0f animations:^{
backgroundImageView.frame = CGRectMake(kRightX, 0, kBackgroundWidth, kBackgroundHeight);
}completion:^(BOOL finished) {
[self animateToLeft];
}];
}
This will not work in your situation.
Because [self.backgroundImageView.layer removeAllAnimations]; this will remove all layer animation which already have added by [self.backgroundImageView.layer addAnimation:/*CABasicAnimation should added here*/];
You can stop this cycle by set boolean variable in completion, then check with boolean variable.
Use a boolean value and if that is set, don't do the next animation -- also cancel pending ones..
e.g.
#interface MyClass () {
BOOL cancelAll;
}
#implementation MyClass
-(void)cancelAnimation {
self.imageView.layer removeAllAnimations]; //!
cancelAll = YES;
}
-(void)animateToLeft{
if(cancelAll)
return;
...
}
-(void)animateToRight{
if(cancelAll)
return;
...
}

Toolbar sethidden=TRUE, sethidden=FALSE

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 ;
}

Resources