I am displaying popped up a view by zoom in zoom out effect. When my app will return from safari after login wtih facebook I am displaying that view. This is working fine in simulator. But it is not working in device. I am checking that thing in ipad . Here is my code:
[MyAppDelegate openSessionWithAllowLoginUI:YES completionBlock:^(BOOL result) {
NSLog(#"Connecte via Joint Page Thank you");
if (result) {
NSLog(#"%# %d ", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation],[[[NSUserDefaults standardUserDefaults] valueForKey:#"isSender"]boolValue]);
if([[[NSUserDefaults standardUserDefaults] valueForKey:#"isSender"]boolValue]==0 && [[[NSUserDefaults standardUserDefaults] valueForKey:#"isServiceProvider"] boolValue]==0){
lbl_register.font=[UIFont fontWithName:GZFont size:16];
lbl_serviceProvider.font=[UIFont fontWithName:GZFont size:14];
lbl_customer.font=[UIFont fontWithName:GZFont size:14];
SelectionView.center=self.view.center;
SelectionView.layer.borderColor=[[UIColor blackColor] CGColor];
SelectionView.layer.borderWidth=1.0;
SelectionView.layer.cornerRadius=5;
SelectionView.layer.masksToBounds=YES;
[UIView animateWithDuration:0.4 animations:^{
SelectionView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1);
} completion:^(BOOL finished) {
NSLog(#"popped");
SelectionView.center=self.view.center;
[UIView animateWithDuration:0.4 animations:^{
SelectionView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.95,0.95);
} completion:^(BOOL finished) {
// self.view.userInteractionEnabled=NO;
}];
}];
[self.view addSubview:SelectionView];
You try this code
explodedBackgroundView = [[UIView alloc] initWithFrame:self.view.bounds];
explodedView = [[UIView alloc]init];
explodedView.frame = CGRectMake(10, 10, 540, 120);
[explodedBackgroundView setFrame:self.view.bounds];
explodedView.center=CGPointMake(self.view.center.x, self.view.center.y);
[explodedBackgroundView setBackgroundColor: [UIColor blackColor]];
[explodedBackgroundView setAlpha: 0.5];
[self.view addSubview:explodedBackgroundView];
explodedView.layer.cornerRadius=20;
explodedView.transform = CGAffineTransformMakeScale(0.1, 0.1);
UIImageView *imageView=[[UIImageView alloc]initWithFrame:explodedView.bounds ];
[explodedView addSubview:imageView]
[self.view addSubview:explodedView];
explodedView.transform = CGAffineTransformMakeScale(0.1, 0.1);
[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
explodedView.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished){
// do something once the animation finishes, put it here
}];
Related
I have 6 views. I want to animate the constraints one by one, ie, i need the animation on second view only after first, then after second the third and so on. I have added the code in the completion handler of the animations, but it is not working. initial value of all the constraint is set to 300 in storyboard. I want to change it to 0 one by one. Now, only the first animation is working. This is what i have done.
layoutTopFirst.constant = 0.0;
[UIView animateWithDuration:1.0 animations:^{
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
self->layoutTopSecond.constant = 0.0;
[UIView animateWithDuration:1.0 animations:^{
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
self->layoutTopThird.constant = 0.0;
[UIView animateWithDuration:1.0 animations:^{
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
self->layoutTopFourth.constant = 0.0;
[UIView animateWithDuration:1.0 animations:^{
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
self->layoutTopFifth.constant = 0.0;
[UIView animateWithDuration:1.0 animations:^{
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
self->layoutTopSixth.constant = 0.0;
[UIView animateWithDuration:1.0 animations:^{
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
}];
}];
}];
}];
}];
}];
How to do animations one after another?
If only the first one is animating, make sure that
your other five constraint references all point to different vertical constraints ... if they were nil for example, you won't see any changes;
that they're all isActive;
that there aren't any other constraints that are preventing the updated constants from yielding changes.
For what it's worth, you might consider eliminating your tower of completion handlers with keyframe animation, e.g.
CGFloat relativeDuration = 1.0 / 6.0;
[UIView animateKeyframesWithDuration:6 delay:0 options:kNilOptions animations:^{
[UIView addKeyframeWithRelativeStartTime:0 relativeDuration:relativeDuration animations:^{
self.topConstraint1.constant = 0;
[self.view layoutIfNeeded];
}];
[UIView addKeyframeWithRelativeStartTime:1.0 * relativeDuration relativeDuration:relativeDuration animations:^{
self.topConstraint2.constant = 0;
[self.view layoutIfNeeded];
}];
[UIView addKeyframeWithRelativeStartTime:2.0 * relativeDuration relativeDuration:relativeDuration animations:^{
self.topConstraint3.constant = 0;
[self.view layoutIfNeeded];
}];
[UIView addKeyframeWithRelativeStartTime:3.0 * relativeDuration relativeDuration:relativeDuration animations:^{
self.topConstraint4.constant = 0;
[self.view layoutIfNeeded];
}];
[UIView addKeyframeWithRelativeStartTime:4.0 * relativeDuration relativeDuration:relativeDuration animations:^{
self.topConstraint5.constant = 0;
[self.view layoutIfNeeded];
}];
[UIView addKeyframeWithRelativeStartTime:5.0 * relativeDuration relativeDuration:relativeDuration animations:^{
self.topConstraint6.constant = 0;
[self.view layoutIfNeeded];
}];
} completion:nil];
Or, even simpler:
NSArray <NSLayoutConstraint *> *constraints = #[self.topConstraint1, self.topConstraint2, self.topConstraint3, self.topConstraint4, self.topConstraint5, self.topConstraint6];
CGFloat relativeDuration = 1.0 / (CGFloat) constraints.count;
[UIView animateKeyframesWithDuration:totalDuration delay:0 options:kNilOptions animations:^{
for (NSInteger i = 0; i < constraints.count; i++) {
[UIView addKeyframeWithRelativeStartTime: ((CGFloat) i) * relativeDuration relativeDuration:relativeDuration animations:^{
constraints[i].constant = 0;
[self.view layoutIfNeeded];
}];
}
} completion:nil];
That yields:
It would help if you showed all your code (how you setup the constraints, etc).
But, here is a quick example.
It creates 6 labels, with top constraints at 100. Tap the "Do Anim" button to animated them to Top: 0.0 ... tap again to animate back to 100:
#import "SequentialAnimViewController.h"
#interface SequentialAnimViewController () {
NSMutableArray *views;
NSMutableArray *topConstraints;
}
#end
#implementation SequentialAnimViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
[button addTarget:self action:#selector(animViews) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:#"Do Anim" forState:UIControlStateNormal];
button.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1.0];
button.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:button];
[button.centerXAnchor constraintEqualToAnchor:[self.view centerXAnchor]].active = YES;
[button.centerYAnchor constraintEqualToAnchor:[self.view centerYAnchor]].active = YES;
[button.widthAnchor constraintEqualToConstant:200.0].active = YES;
views = [NSMutableArray new];
topConstraints = [NSMutableArray new];
CGFloat x = 40.0;
CGFloat w = 40.0;
UILayoutGuide *g = [self.view safeAreaLayoutGuide];
for (int i = 0; i < 6; i++) {
UILabel *v = [UILabel new];
v.backgroundColor = [UIColor blueColor];
v.textColor = [UIColor yellowColor];
v.textAlignment = NSTextAlignmentCenter;
v.text = [NSString stringWithFormat:#"%i", i];
v.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:v];
[v.widthAnchor constraintEqualToConstant:w].active = YES;
[v.heightAnchor constraintEqualToConstant:w].active = YES;
[v.leadingAnchor constraintEqualToAnchor:g.leadingAnchor constant:x].active = YES;
[topConstraints addObject:[v.topAnchor constraintEqualToAnchor:g.topAnchor constant:100.0]];
[views addObject:v];
x += w + 8;
}
[NSLayoutConstraint activateConstraints:topConstraints];
}
-(void)animViews {
__block int i = 0;
__block CGFloat newConstant = ((NSLayoutConstraint *)self->topConstraints[0]).constant == 0.0 ? 100.0 : 0.0;
((NSLayoutConstraint *)self->topConstraints[i++]).constant = newConstant;
[UIView animateWithDuration:1.0 animations:^{
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
((NSLayoutConstraint *)self->topConstraints[i++]).constant = newConstant;
[UIView animateWithDuration:1.0 animations:^{
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
((NSLayoutConstraint *)self->topConstraints[i++]).constant = newConstant;
[UIView animateWithDuration:1.0 animations:^{
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
((NSLayoutConstraint *)self->topConstraints[i++]).constant = newConstant;
[UIView animateWithDuration:1.0 animations:^{
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
((NSLayoutConstraint *)self->topConstraints[i++]).constant = newConstant;
[UIView animateWithDuration:1.0 animations:^{
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
((NSLayoutConstraint *)self->topConstraints[i++]).constant = newConstant;
[UIView animateWithDuration:1.0 animations:^{
[self.view layoutIfNeeded];
} completion:^(BOOL finished) {
NSLog(#"All Done!");
}];
}];
}];
}];
}];
}];
}
#end
I am trying animate and get transferred only when the animation gets finished..but everything works fine except the segue...when I clicked the button it navigates to another page...before the animation gets finished... I a new bee to ios please mention my mistake...
#import "ViewController.h"
#import <Lottie/lottie.h>
#interface ViewController ()
#property UIView * AnimatedViewForLoading;
#property LOTAnimationView * LottieAnimationHourGlass;
#end
-(IBAction)ButtonTouched:(id)sender {
self.AnimatedViewForLoading = [[UIView alloc] initWithFrame:CGRectMake(118, 318, 200, 150)];
[self.AnimatedViewForLoading setBackgroundColor:[UIColor clearColor]];
// self.AnimatedViewForLoading.alpha = 0.0f;
//AnimatedViewForLoading.backgroundColor = UIColor.lightGrayColor;
self.LottieAnimationHourGlass = [LOTAnimationView animationNamed:#"hourglass"];
self.LottieAnimationHourGlass.frame = CGRectMake(118, 318, 200, 150);
// if(!UIAccessibilityIsReduceTransparencyEnabled()){
// self.view.backgroundColor = [UIColor clearColor];
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *blureffectview = [[UIVisualEffectView alloc]initWithEffect:blurEffect];
blureffectview.frame = self.view.bounds;
blureffectview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:blureffectview];
[self.view insertSubview:_AnimatedViewForLoading aboveSubview:blureffectview];
//[self.view sendSubviewToBack:_AnimatedViewForLoading];
[self.view insertSubview:_LottieAnimationHourGlass aboveSubview:_AnimatedViewForLoading];
[_LottieAnimationHourGlass play];
_LottieAnimationHourGlass.loopAnimation = YES;
// }else{
//self.view.backgroundColor = [UIColor blackColor];
// }
self.AnimatedViewForLoading.transform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView animateWithDuration:10.0 delay:3.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
self.AnimatedViewForLoading.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1);
} completion:^(BOOL finished) {
NSLog(#"oopssssss..........");
[UIView animateWithDuration:0.3/2 animations:^{
self.AnimatedViewForLoading.transform = CGAffineTransformIdentity;
}];
if (finished == true) {
[self dismissViewControllerAnimated:YES completion:nil];
[self performSegueWithIdentifier:#"YourTimeisLoading" sender:_AnimatedViewForLoading];
}
}];
//[self dismissViewControllerAnimated:YES completion:nil];
}
scenario 1:
check your second completion
[UIView animateWithDuration:10.0 delay:3.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
self.AnimatedViewForLoading.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1);
} completion:^(BOOL finished) {
NSLog(#"oopssssss..........");
[UIView animateWithDuration:0.3/2 animations:^{
self.AnimatedViewForLoading.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) {
[self dismissViewControllerAnimated:YES completion:nil];
[self performSegueWithIdentifier:#"YourTimeisLoading" sender:_AnimatedViewForLoading];
}];
}];
scenario 2:
ensure once your performSegueWithIdentifier is connected with VC not directed in button.If its directly connected with your UIButton,it won't consider anything inside the action handler.
I'm having some issues with my animations. The intended result is that the UIButton's should both move to their positions, and once they reach their positions they must oscillate upwards and downwards, subtly, to simulate reaching the end of their bungee chord, if you will. The result I'm achieving is that every animation apart from the oscillation is executing perfectly. Why is this? (The oscillation animation I refer to is, of course, the spring animateWithDuration method.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
_orText.alpha = 0;
//Email login button properties
_emailLoginForwardButton.layer.cornerRadius = _emailLoginForwardButton.frame.size.width / 2;
self.emailLoginForwardButton.layer.borderWidth = 1.5f;
self.emailLoginForwardButton.layer.borderColor = [UIColor whiteColor].CGColor;
[self.emailLoginForwardButton setImageEdgeInsets:UIEdgeInsetsMake(7, 7, 7, 7)];
_emailLoginForwardButton.frame = CGRectMake(77, 700, 40, 40);
[UIView animateWithDuration:0.5
animations:^
{
_emailLoginForwardButton.frame = CGRectMake(77, 470, 40, 40);
}
completion:^(BOOL finished)
{
[UIView animateWithDuration:0.3
delay:0.6
usingSpringWithDamping:0.2
initialSpringVelocity:0.4
options:0
animations:^(void){}
completion:^(BOOL finished)
{
_orText.text = #"or";
[UIView animateWithDuration:0.4
animations:^
{
[_orText setAlpha:1];
}
];
}
];
}
];
//Google login button properties
_googleLoginForwardButton.layer.cornerRadius =_googleLoginForwardButton.frame.size.width / 2;
self.googleLoginForwardButton.layer.borderWidth = 1.5f;
self.googleLoginForwardButton.layer.borderColor = [UIColor grayColor].CGColor;
_googleLoginForwardButton.frame = CGRectMake(257, 700, 40, 40);
[UIView animateWithDuration:0.5
delay:0.4
options:0
animations:^
{
_googleLoginForwardButton.frame = CGRectMake(257, 470, 40, 40);
}
completion:^(BOOL finished)
{
[UIView animateWithDuration:0.3
delay:0.3
usingSpringWithDamping:0.2
initialSpringVelocity:0.4
options:0
animations:^
{
}
completion:^(BOOL finished)
{
}
];
}
];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.googleLoginForwardButtonBottomConstraints.constant = -100.0;//e.g
self.emailLoginForwardButtonBottomConstraints.constant = -100.0;//e.g
[UIView animateWithDuration:0.6
delay:0.6
usingSpringWithDamping:0.2
initialSpringVelocity:0.4
options:0
animations:^(void){
self.googleLoginForwardButtonBottomConstraints.constant = 40.0;//e.g
self.emailLoginForwardButtonBottomConstraints.constant = 40.0;//e.g
[self.view layoutIfNeeded];
}
completion:^(BOOL finished) {
}];
}
I have run this code and its working. Hope it will help you.
[UIView animateWithDuration:1
delay:0.6
usingSpringWithDamping:0.42
initialSpringVelocity:0.1
options:0
animations:^(void)
{
_orText.text = #"or";
[UIView animateWithDuration:0.7
animations:^
{
[_orText setAlpha:1];
}];
[UIView animateWithDuration:0.6
animations:^
{
_emailLoginForwardButton.frame = CGRectMake(77, 470, 40, 40);
}];
[UIView animateWithDuration:0.6
animations:^
{
_googleLoginForwardButton.frame = CGRectMake(257, 470, 40, 40);
}
];
[self.view layoutIfNeeded];
}
completion:^(BOOL finished) {
}];
This was my solution, however there was more I wanted to do with this code. I wanted to make both buttons move at different intervals, and an if statement won't work here, for some reason. Also, I only wanted this to initialise when another action has taken place, which is still possible to do, but I'd prefer to be able to make them move at different times.
I want to create a custom alertView that works like instagram app (login/signin view when user enters wrong password or email). The alert animation should drop down and pause for the user to read for about 2 seconds, then the alertView goes up again. How can I do this?
Here is what I have now:
- (UIView *) createAlertViewWithViewController:(UIViewController *)viewController andText:(NSString *)alertText
{
alertView = [[UIView alloc] init];
[alertView setBackgroundColor:ALERT_VIEW_COLOR];
[alertView setFrame:ALERT_VIEW_HIDE_FRAME];
UILabel *alertViewLabel = [[UILabel alloc] init];
[alertViewLabel setFrame:CGRectMake(viewController.view.bounds.origin.x, 7, viewController.view.bounds.size.width, ALERT_VIEW_HEIGHT)];
[alertViewLabel setTextAlignment:NSTextAlignmentCenter];
[alertViewLabel setTextColor:[UIColor whiteColor]];
[alertViewLabel setFont:[UIFont systemFontOfSize:13.0f]];
[alertViewLabel setText:alertText];
[alertView addSubview:alertViewLabel];
CGPoint originalCenter = alertView.center;
[UIView animateWithDuration:0.5
animations:^{
CGPoint center = alertView.center;
center.y += ALERT_VIEW_HEIGHT;
alertView.center = center;
}
completion:^(BOOL finished){
[UIView animateWithDuration:3.0
animations:^{
alertView.center = originalCenter;
}
completion:^(BOOL finished){
;
}];
}];
return alertView;
}
My code right now goes down and goes up immediately but what I want is, when it finishes the drop down animation it pauses for around 2 seconds then do the goes up animation.
I have been searching for 3 days now, but I haven't found anything one this.
Example image when it should pause for 2 seconds:
Im guessing you are looking for one of the extended versions of [UIView animateWithDuration:...
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion
Pass in a delay to wait your animation.
Would you like a this library?
https://github.com/problame/CSNotificationView
Example
[CSNotificationView showInViewController:self
tintColor:[UIColor colorWithRed:0.000 green:0.6 blue:1.000 alpha:1]
image:nil
message:#"What's the meetup called?"
duration:2.f];
Try this:
UILabel *myLable=[[UILabel alloc]init];
myLable.frame=CGRectMake(0, -50, 320, 50);
myLable.backgroundColor=[UIColor grayColor];
myLable.textAlignment=NSTextAlignmentCenter;
myLable.text=#"Your Error Message";
[self.view addSubview:myLable];
[self ShowAnimation:myLable currentFrame:CGRectMake(0, -50, 320, 50) newFrame:CGRectMake(0, 0, 320, 50)];
.
-(void)ShowAnimation:(UILabel *)aLable currentFrame:(CGRect)aCurrentFrame newFrame:(CGRect)aNewFrame
{
[aLable setFrame:aCurrentFrame];
[UIView animateWithDuration:1.5 animations:^{
[aLable setFrame:aNewFrame];
}completion:^(BOOL finished)
{
[aLable setFrame:aNewFrame];
[UIView animateWithDuration:1.5 delay:2.0 options:UIViewAnimationOptionCurveEaseIn
animations:^{
[aLable setFrame:aCurrentFrame];
}
completion:^(BOOL finished) {
}];
}];
}
I created this animation and I entered through the stop animation
[UIView setAnimationDidStopSelector:#selector (TermineAnimazioneGoPointAssignedWithDelay)] ;
When the animation part of the SetAnimationDidStop is not called ... Can you tell me why and where am I doing wrong ?
This is all the way animation :
-(void)setViewStatusGoPointassigned {
ViewgoPointAssignMessage = [[UIView alloc] initWithFrame:CGRectMake(115, 150, 100, 100) ];
ViewgoPointAssignMessage.backgroundColor = [UIColor colorWithRed:(77/255.0) green:(108/255.0) blue:(143/255.0) alpha:(1)];
[ViewgoPointAssignMessage.layer setCornerRadius:10.0f];
[ViewgoPointAssignMessage.layer setMasksToBounds:YES];
[UIView animateWithDuration:0.2 animations:^{
ViewgoPointAssignMessage.transform = CGAffineTransformMakeScale(1.05, 1.05);
ViewgoPointAssignMessage.alpha = 0.8; }
completion:^(BOOL finished){
[UIView animateWithDuration:2/15.0 animations:^{
ViewgoPointAssignMessage.transform = CGAffineTransformMakeScale(0.9, 0.9);
ViewgoPointAssignMessage.alpha = 0.9; }
completion:^(BOOL finished) {
[UIView animateWithDuration:1/7.5 animations:^{
ViewgoPointAssignMessage.transform = CGAffineTransformIdentity;
ViewgoPointAssignMessage.alpha = 1.0; } ];
} ];
} ];
[self.view addSubview:ViewgoPointAssignMessage];
[UIView setAnimationDidStopSelector:#selector(TermineAnimazioneGoPointAssignedWithDelay)];
}
-(void)TermineAnimazioneGoPointAssignedWithDelay {
[self performSelector:#selector(EliminazioneViewAfterDelay) withObject:self afterDelay:0.01];
}
-(void)EliminazioneViewAfterDelay {
CGRect endREct;
endREct = CGRectMake(350 , 0 , 330, 90);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.005];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(EliminaAnimazione)];
ViewgoPointAssignMessage.frame = endREct;
[UIView commitAnimations];
}
- (void)EliminaAnimazione {
[ViewgoPointAssignMessage removeFromSuperview];
}
First of all, to answer your question.
You may try
[UIView animateWithDuration:(NSTimeInterval)duration animations:^(void)animations completion:^(BOOL finished)completion]
and call [self TermineAnimazioneGoPointAssignedWithDelay] in the completion.
Secondly, [UIView setAnimationDidStopSelector:#selector(TermineAnimazioneGoPointAssignedWithDelay)] doesn't work because according to the reference, setAnimationDidStopSelector must be called between calls to the beginAnimations:context: and commitAnimations methods. Since your code doesn't comply to this rule, the function does not work either.
Hopefully it explains! Good Luck!