iOS can't moving UIView - ios

NSLog(#"Before: %f",_inputView.frame.origin.y);
[UIView animateWithDuration:animationDuration animations:^{
[_inputView setFrame: CGRectMake(_inputView.frame.origin.x, 0, _inputView.frame.size.width, _inputView.frame.size.height)];
}completion:^(BOOL finished){
NSLog(#"After: %f",_inputView.frame.origin.y);
}];
I use this code to move my UIView but it doesn't move.
(Log -> Before: 520.00 After: 520.00)

Related

Animation is happening in reverse

I'm making a simple animation where when a button is tapped it will change from current position to a certain point. But what's happening is the opposite: it goes from the destination point to the original position. Here's my code:
[UIView animateWithDuration:1.0
delay:0.0
usingSpringWithDamping:0.2
initialSpringVelocity:0.0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
[self.view layoutIfNeeded];
CGFloat amount = 100;
self.checkButton.frame = CGRectOffset(self.checkButton.frame, amount, 0);
} completion:^(BOOL finished) {
}];
Make an outlet to the constraint that determine the horizontal position of the checkButton. e.g."hPos".
- (IBAction)tapHandler:(id)sender {
self.hPos.constant = self.hPos.constant + 100;
[UIView animateWithDuration:1.0
delay:0.0
usingSpringWithDamping:0.2
initialSpringVelocity:0.0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{ [self.view layoutIfNeeded]; }
completion:nil];
}

UIView setHidden:NO like dropdown

I have a UIView which is initially hidden. I need to setHidden:NO (visible) with dropdown effect...
There's my simple code without effect
-(IBAction)btnAbrirDestaquesClick:(id)sender {
[self.viewDestaques setHidden:NO];
}
A simpler alternative to UIDynamicAnimator in iOS 7 is Spring Animation (a new and powerful UIView block animation), which can give you nice bouncing effect with damping and velocity:
[UIView animateWithDuration:duration
delay:delay
usingSpringWithDamping:damping
initialSpringVelocity:velocity
options:options animations:^{
//Animations
[self.viewDestaques setHidden:NO];
}
completion:^(BOOL finished) {
//Completion Block
}];
If you simply want to animate it try something like this:
[UIView animateWithDuration:.5 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
self.viewDestaques.frame = CGRectMake(0, 0, 320,30);
} completion:^(BOOL finished) {
[UIView animateWithDuration:.5 delay:2.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
self.viewDestaques.frame = CGRectMake(0, -30, 320,30);
} completion:^(BOOL finished) {
}];
}];
It worked for me:
-(IBAction)btnAbrirDestaquesClick:(id)sender {
[self.viewDestaques setTranslatesAutoresizingMaskIntoConstraints:YES]; //respeita o frame que eu setar, independentemente das constraints
[self.viewDestaques setFrame:CGRectMake(self.viewDestaques.frame.origin.x, self.viewDestaques.frame.origin.y, self.viewDestaques.frame.size.width, 0)];
[self.viewDestaques setHidden:NO];
while (self.viewDestaques.frame.size.height < self.frameViewDestaquesOriginal.size.height) {
[UIView animateWithDuration:2.0 animations:^{
[self.viewDestaques setFrame:CGRectMake(self.viewDestaques.frame.origin.x, self.viewDestaques.frame.origin.y, self.viewDestaques.frame.size.width, self.view.frame.size.height + 10)];
}completion: ^(BOOL completed){
}];
}
}

uilabel animating to original position

I'm trying to animate a UILabel frame to a position in the middle of the screen. Instead, it seems to be animating from somewhere outside the view back to its original position.
[UIView beginAnimations:#"labelAnim" context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationCurve: UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:1.0];
[self.scoreLabel setFrame:self.endScoreFrame];
[UIView commitAnimations];
Here are the starting and ending frames:
Start Frame: {{10, 30}, {144, 21}}
Final Frame: {{93.75, 158.71438598632812}, {187.5, 46.875}}
Try this code
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationCurveEaseIn | UIViewAnimationOptionBeginFromCurrentState
animations:^{
[self.scoreLabel setFrame:self.endScoreFrame];
} completion:^(BOOL finished) {
NSlog("completed");
}];
And make sure your endScoreFrame have the correct new position coordinates:
NSLog(#"%#", NSStringFromCGRect(self.endScoreFrame));
I have tested this code with the values of your old and new frames and it works fine:
#property (nonatomic, strong) UILabel *lbl;
ViewDidLoad:
self.lbl = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, 144, 21)];
self.lbl.text = #"mylabel";
[self.view addSubview:self.lbl] ;
Action
-(void)btnClick:(id)sender
{
CGRect newFrame = CGRectMake(93.75, 158.71438598632812, 187.5, 46.875);
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationCurveEaseIn | UIViewAnimationOptionBeginFromCurrentState
animations:^{
self.lbl.frame = newFrame ;
} completion:^(BOOL finished) {
}];
}
I found the problem. I had forgotten that I had the label I was trying to animate in Interface Builder, so it was being overridden.

Show and hide UITableView with animation

I'm trying to show and hide a tableView with an animation "transition from left to right & right to left"
This what i already tired it worked but after using a random values in the CGRectMake,
Do anyone can help me to fix it please
-(void)Display:(UITableView *)tableView :(UIView *)view{
tableView.alpha=1;
[UIView animateWithDuration:0.35
animations:^{
tableView.frame = CGRectMake(-209, 440, 180, 209);
}
completion:^(BOOL finished){
[tableView setHidden:YES];
}
];
}
-(void)Hide:(UITableView *)tableView :(UIView *)view :(int )tb{
tableView.alpha=1;
[tableView setHidden:NO];
[UIView animateWithDuration:.45
animations:^{
tableView.frame = CGRectMake(3, 442, 180, 209);
}
];
}
You can use this code:
[UIView transitionFromView:firstView
toView:secondView//table view
duration:0.5
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:^(BOOL finished) {
[firstView.superView addSubview:secondView];
[firstView.superView sendSubviewToBack:firstView];
}];
It's hard to tell from your question but by "transition from left to right & right to left"
do you want something like this...?
For animating out left
[UIView animateWithDuration:1.0f
delay:0.0f
options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut
animations:^{
self.tableView.frame = CGRectMake(0.0f, -self.tableView.frame.size.width, self.tableView.frame.size.width, self.tableView.frame.size.height);
}
completion:NULL];
For animating out right
[UIView animateWithDuration:1.0f
delay:0.0f
options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut
animations:^{
self.tableView.frame = CGRectMake(0.0f, self.view.bounds.size.width, self.tableView.frame.size.width, self.tableView.frame.size.height);
}
completion:NULL];
For animating in
[UIView animateWithDuration:1.0f
delay:0.0f
options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveEaseInOut
animations:^{
self.tableView.frame = CGRectMake(0.0f, 0.0f, self.tableView.frame.size.width, self.tableView.frame.size.height);
}
completion:NULL];
You can put table reloads etc. in your completion blocks? and then animate the tableView back in?
If you want animation like Facebook then use :- ECSlidingViewController
http://kingscocoa.com/tutorials/slide-out-navigation/
Or
If you want normal animation then set frame and reduce alpha from 1.0 to 0.0 with duration.

animateKeyframesWithDuration make screen Not responding after animation

I use animateKeyframesWithDuration to simple animate my view:
[UIView animateKeyframesWithDuration:1.0 delay:0.0 options:0 animations:^{
[UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.5 animations:^{
containerView.center = CGPointMake(containerView.center.x, 150);
}];
[UIView addKeyframeWithRelativeStartTime:0.5 relativeDuration:0.5 animations:^{
containerView.center = oldCenter;
}];
}completion:^(BOOL finished) {
}];
After the animation finished (completion block called with finished = YES), the UIViewController isn't responsive, e.g. I can't press any UIButton on top the UIViewController.
Why that?
I added this line in the completion block:
[transitionContext completeTransition:NO];
That fix my problem.

Resources