iOS Frameworks needed for animation - ios

I have a simple animation to fade out an image but it is not working. The method is being called but no animation. What frameworks are required in the project for this? Think that might be the issue since the image just goes right to alpha:0 with no animation.
#import "TutorialViewController.h"
#interface TutorialViewController ()
#end
#implementation TutorialViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self popupImage];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)popupImage
{
NSLog(#"It worked");
_imageView.hidden = NO;
_imageView.alpha = 1.0f;
// Then fades it away after 2 seconds (the cross-fade animation will take 0.5s)
[UIView animateWithDuration:1
delay:2
options:UIViewAnimationOptionCurveEaseIn
animations:^{
_imageView.alpha = .0f;
}
completion:^(BOOL finished) {
// Once the animation is completed and the alpha has gone to 0.0, hide the view for good
_imageView.hidden = NO;
}];
}

Related

Implementing Firebase's GoogleSignIn results in 2 iterations of the same view controller popping up, one on top of the other

Essentially, whenever a user clicks on a button that transitions them to a screen where they can sign in using their google credentials, the end-result is that 2 of the same exact screen pop up. The second screen has a useable button, which functions perfectly, however when they use the button I've implemented, which allows them to transition to previous screens in the ViewController stack, the result is that the application crashes. Now, I have no idea why there are even 2 iterations of this view controller in the first place, is there anyone that can help diagnose my issue? I will attach the code for the view controller below, however I must mention that this same behaviour is observed with only the " [GIDSignIn sharedInstance].uiDelegate = self;" being preserved (I.E. If I delete all other google sign in related functions, it still displays this behaviour). The code:
#import "FifthViewController.h"
#import Firebase;
#import GoogleSignIn;
#interface FifthViewController ()
#property (weak, nonatomic) IBOutlet UIButton *googleLoginBackButton;
#property (weak, nonatomic) IBOutlet GIDSignInButton *googleLoginButton;
#end
#implementation FifthViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self setNeedsStatusBarAppearanceUpdate];
[GIDSignIn sharedInstance].uiDelegate = self;
[GIDSignIn sharedInstance].delegate = self;
_googleLoginBackButton.layer.cornerRadius = _googleLoginBackButton.frame.size.width / 2;
self.googleLoginBackButton.layer.borderWidth = 1.5f;
self.googleLoginBackButton.layer.borderColor = [UIColor whiteColor].CGColor;
[_googleLoginBackButton addTarget:self action:#selector(backButtonHighlightBorder) forControlEvents:UIControlEventTouchDown];
[_googleLoginBackButton addTarget:self action:#selector(backButtonUnhighlightBorder) forControlEvents:UIControlEventTouchUpInside];
[_googleLoginBackButton addTarget:self action:#selector(backButtonUnhighlightBorder) forControlEvents:UIControlEventTouchDragExit];
_googleLoginButton.style = kGIDSignInButtonStyleWide;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
- (void)backButtonHighlightBorder
{
_googleLoginBackButton.layer.borderColor = [UIColor colorWithRed:0.61 green:0.00 blue:0.02 alpha:1.0].CGColor;
}
- (void)backButtonUnhighlightBorder
{
_googleLoginBackButton.layer.borderColor = [UIColor whiteColor].CGColor;
}
- (IBAction)dismissViewControllerAnimated:(UIButton *)sender
{
[UIView animateWithDuration:0.2
animations:^
{
_googleLoginBackButton.frame = CGRectMake(168, 700, 40, 40);
}
completion:^(BOOL finished)
{
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
[UIView animateWithDuration:0.1
delay:0.45
options:0
animations:^
{
_googleLoginBackButton.frame = CGRectMake(168, 564, 40, 40);
}
completion:^(BOOL finished)
{
}
];
}
];
}
- (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user withError:(NSError *)error
{
if (!error)
{
[self performSegueWithIdentifier:#"toHome" sender:self];
}
}
#end
For any of you as neglectful as I am, double check the implementation of the controller that navigates to this one. I found that I had a manual segue in the actual GUI Storyboard area that navigated to a controller on the press of a button, however I also implemented a segue programatically. The simple solution is to convert the GUI Storyboard segue into one that links between controllers, not between actions and controllers.

Animating a UITextview in a UIToolbar issue

I am trying to animate a UITextView to expand the to the width of its containing UIToolbar.
But it animates weird, jumping around.
Can anyone help me make understand why my textbox jumps around?
#define ANIMATION_DURATION 0.5
#define ANIMATION_DELAY 0.03
#interface WebViewController () <UITextFieldDelegate>{
CGRect URLBAR_DEFAULT;
}
-(void)viewDidLoad{
self.txtURLBar = [[UITextField alloc] init];
self.txtURLBar.bounds = CGRectMake(0, 0, 100, 30);
self.txtURLBar.delegate = self;
self.txtURLBar.backgroundColor = [UIColor lightGrayColor];
self.txtURLBar.clearButtonMode = UITextFieldViewModeWhileEditing;
URLBAR_DEFAULT = self.txtURLBar.frame; //KEEP A REFRENCE TO THE ORIGINAL SIZE
}
//START EDITING EXPAND TO FULL WIDTH
- (void)textFieldDidBeginEditing:(UITextField *)textField {
[UIView animateWithDuration:ANIMATION_DURATION delay:ANIMATION_DELAY options:UIViewAnimationOptionCurveLinear animations:^{
[_txtURLBar setFrame:CGRectMake(3, URLBAR_DEFAULT.origin.y, self.view.frame.size.width - 10, URLBAR_DEFAULT.size.height)];
} completion:^(BOOL finished) {
}];
}
//END EDITING SHRINK BACK TO SMALL SIZE
- (void)textFieldDidEndEditing:(UITextField *)textField {
[UIView animateWithDuration:ANIMATION_DURATION delay:ANIMATION_DELAY options:UIViewAnimationOptionCurveEaseOut animations:^{
[_txtURLBar setFrame:CGRectMake(URLBAR_DEFAULT.origin.x, URLBAR_DEFAULT.origin.y, URLBAR_DEFAULT.size.width, URLBAR_DEFAULT.size.height)];
} completion:^(BOOL finished) {
}];
}
The problem may be due to the frame being set in textFieldDidBeginEditing, textFieldDidEndEditing is different. I've done the small POC with same code of yours as below. It's working fine.
#interface ViewController ()
#property (weak, nonatomic) IBOutlet UITextField *resizeableTextField;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//START EDITING EXPAND TO FULL WIDTH
- (void)textFieldDidBeginEditing:(UITextField *)textField {
[UIView animateWithDuration:0.5 delay:0.03 options:UIViewAnimationOptionCurveLinear animations:^{
self.resizeableTextField.frame = CGRectMake(CGRectGetMinX(self.resizeableTextField.frame), CGRectGetMinY(self.resizeableTextField.frame), self.resizeableTextField.frame.size.width + 40, CGRectGetHeight(self.resizeableTextField.frame));
} completion:^(BOOL finished) {
}];
}
//END EDITING SHRINK BACK TO SMALL SIZE
- (void)textFieldDidEndEditing:(UITextField *)textField {
[UIView animateWithDuration:0.5 delay:0.03 options:UIViewAnimationOptionCurveEaseOut animations:^{
self.resizeableTextField.frame = CGRectMake(CGRectGetMinX(self.resizeableTextField.frame), CGRectGetMinY(self.resizeableTextField.frame), self.resizeableTextField.frame.size.width - 40, CGRectGetHeight(self.resizeableTextField.frame));
} completion:^(BOOL finished) {
}];
}
#end

Change TableView height When Tapped(using autolayout in xib)

My ViewController looks like this when initially loaded:
When show button is tapped it must change like this:
my code is:
- (IBAction)show:(id)sender {
[self change];
[tableView reloadData];
}
- (IBAction)close:(id)sender {
[self change];
[tableView reloadData];
}
-(void)change{
//assigning initial bounds to frame-1
CGRect frame1=CGRectMake(0, _pastProcessTV.frame.origin.y, self.view.bounds.size.width, self.pastProcessTV.bounds.size.height);
//assigning new bounds to frame-2
CGRect frame2=CGRectMake(0, **CGFloat y**,self.view.bounds.size.width,***CGFloat height***);
if (_showFullButton.isTouchInside) {
tableView.frame = frame2;
}
else{
tableview.frame = frame1;
}
}
I tried different ways. it is not working.can anyone help me in giving Y-coordinate and width
As you are using autolayout you have to take outlet of topconstraint of the tableview and when you want to expand it set its value to 0
So it will work as expected
if you are using iOS 7
[self.view layoutIfNeeded] is compulsary
If you have to use auto layout, please try like this picture
Make Layout Constraint Property
And try this code
#import "ViewController.h"
#interface ViewController ()
{
CGFloat oldtableViewTopValue;
}
#property (weak, nonatomic) IBOutlet NSLayoutConstraint *tableViewTopLC;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.view setNeedsLayout];
[self.view layoutIfNeeded];
oldtableViewTopValue = _tableViewTopLC.constant;
}
- (IBAction)showBtnAction:(id)sender
{
[UIView animateWithDuration:0.5f animations:^{
_tableViewTopLC.constant = (_tableViewTopLC.constant==oldtableViewTopValue ? 0 : oldtableViewTopValue);
[self.view setNeedsLayout];
[self.view layoutIfNeeded];
}];
}
#end
Please turn off autolayout from Storyboard

iOS Make Buttons and Labels appear after some Time

Currently I am creating an App when you first launch it, there is some Introduction Text and 2 Buttons. 1 Button to skip the Tutorial and the other one to do the Tutorial. I want that these 2 Buttons and those Labels appear after a certain Time and with an Fade In animation. Could anyone give me some code examples? I already tried searching but the results weren't helpful for me.
I Updatet some Code. Now looks like this:
.h File:
#interface startViewController : UIViewController {
IBOutlet UIButton *notourb;
IBOutlet UIButton *tourb;
IBOutlet UILabel *welcomeLabel;
}
- (void)shownotourb;
- (void)showtourb;
- (void)showwLabel;
And the .m File (I will only show the code from the buttons because I figured out how to do the Labels in another way):
- (void)viewDidLoad
{
[super viewDidLoad];
[self performSelector:#selector(shownotourb) withObject:nil afterDelay:2.0];
[self performSelector:#selector(showtourb) withObject:nil afterDelay:2.5];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)shownotourb {
[UIView animateWithDuration:10.0
delay:1.0
options:UIViewAnimationCurveEaseInOut
animations:^ {
[self.view addSubview:notourb];
}
completion:^(BOOL finished){}];
}
- (void)showtourb {
[UIView animateWithDuration:10.0
delay:1.0
options:UIViewAnimationCurveEaseInOut
animations:^ {
[self.view addSubview:tourb];
}
completion:^(BOOL finished){}];
}
create a method which will add the buttons to the view, and use the performSelector:afterDelay method to add them like this:
in your viewDidLoad:
[self performSelector:#selector(addButtonsToView) withObject:nil afterDelay:5.0];
and add this method to add your buttons:
-(void)addButtonsToView
{
[UIView animateWithDuration:10.0
delay:1.0
options:UIViewAnimationCurveEaseInOut
animations:^ {
[self.view addSubview:button1];
[self.view addSubview:button2];
}
completion:^(BOOL finished){}];
}
hope it helps :)

Move UIImageView from A to B

I need to move an UIImageView from x,y to x,y1.
This is what i have. I tried lots of different codes in -(void)animation, most using animateWithDuration but none seems to work. It just doesn't do anything. I must be missing something. Is .h correct? How would you make the image move? I then have to loop that, how can i do that? It's my first time with animate, I can't figure out what to do, it has to be simple. Thanks in Advance.
in .h I connected it this way
#import <UIKit/UIKit.h>
#interface ImageBeaconViewController : UIViewController {
__weak IBOutlet UIImageView *blueView;
}
#end
the in .m I've got
- (void)viewDidLoad
{
[self animation];
[super viewDidLoad];
}
....
- (void)animation{
[UIView animateWithDuration:3 animations:^{
blueView.alpha = 1;
blueView.center = CGPointMake(blueView.center.x , blueView.center.y +??);
}];
}
??= I still have to decide how much I want it to move
This way the app crashes as soon as I get to the screen with the animation
Add Method Like This:
- (void) animateToPoint:(CGPoint)point {
[UIView animateWithDuration:3 animations:^{
blueView.alpha = 1;
blueView.center = point;
}];
}
Call like this:
- (void) viewDidAppear:(BOOL)animated {
int distanceToSlide = 40; // will slide down 40px (use -40 to go up)
CGPoint targetPoint = CGPointMake(blueView.center.x, blueView.center.y + distanceToSlide);
[self animateToPoint:targetPoint];
}
NOTE
Notice that I put your animation call in viewDidAppear if you animate in viewDidLoad you won't see anything because your view isn't displayed yet.
If it's still not moving, make sure "useAutolayout" is not selected check this:
Just because I already built it, try this for tap to animate:
In your viewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]init];
tap.numberOfTapsRequired = 1;
[tap addTarget:self action:#selector(handleTap:)];
[self.view addGestureRecognizer:tap];
}
Then, use these:
- (void) handleTap:(UITapGestureRecognizer *)tap {
int distanceToSlide = 40; // will slide down 40px (use -40 to go up)
CGPoint targetPoint = CGPointMake(blueView.center.x, blueView.center.y + distanceToSlide);
[self animateToPoint:targetPoint];
}
- (void) animateToPoint:(CGPoint)point {
[UIView animateWithDuration:3 animations:^{
blueView.alpha = 1;
blueView.center = point;
}];
}
Here's a way to loop it:
#implementation ImageBeaconViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
pointA = CGPointMake(40, 40);
pointB = CGPointMake(250, 350);
blueView.center = pointA;
}
- (void) viewDidAppear:(BOOL)animated {
[self animate];
}
- (void) animate {
if (CGPointEqualToPoint(_blueView.center, pointA)) {
[self animateToPoint:pointB];
}
else {
[self animateToPoint:pointA];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void) animateToPoint:(CGPoint)point {
[UIView animateWithDuration:1.0 animations:^{
_blueView.alpha = 1;
_blueView.center = point;
} completion:^(BOOL finished) {
if (finished) {
[self animate];
}
}];
}
#end
[UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
blueView.alpha = 1;
blueView.center = CGPointMake(blueView.center.x , blueView.center.y + 100);
} completion:^(BOOL finished) {
//if you need any thing after animation is done
}];
this is them code for animation i have

Resources