App slowness after using UIView Animations - ios

So I have an App of which I animate some UI Elements as soon as the app opens. These animations are done using simple UIView Animations. Below is a sample of the viewDidLoad portion
//animate settings in the frame
CGRect settingsFrame = settingsView.frame;
settingsFrame.origin.x = -104;
settingsFrame.origin.y = 457;
settingsView.frame = settingsFrame;
//animate about in the frame
CGRect aboutFrame = aboutView.frame;
aboutFrame.origin.x = -104;
aboutFrame.origin.y = 457;
aboutView.frame = aboutFrame;
And here is a the corresponding method portion that is called.
CGRect settingsFrame = settingsView.frame;
settingsFrame.origin.x = 0; // new x coordinate
settingsFrame.origin.y = 457; // new y coordinate
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration: 1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
settingsView.frame = settingsFrame;
CGRect aboutFrame = aboutView.frame;
aboutFrame.origin.x = 104; // new x coordinate
aboutFrame.origin.y = 457; // new y coordinate
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration: 1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
aboutView.frame = aboutFrame;
There are 4 more matching sets of code to finish out the animation. My problem is, whenever the viewDidLoad portion is enabled (not commented out) it slows down the other transitions to xib's in my App. Do you guys have any idea how I can keep these animations but not have the slow transitions?
In addition to that, I should say this is being developed on iOS 7 and Xcode 5 Developer Preview, so I'm not ruling out a bug...

You forgot to add commitAnimations at the end of the animation block...
Do below, you problem will be fixed.
CGRect settingsFrame = settingsView.frame;
settingsFrame.origin.x = 0; // new x coordinate
settingsFrame.origin.y = 457; // new y coordinate
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration: 1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
settingsView.frame = settingsFrame;
**[UIView commitAnimations];**
CGRect aboutFrame = aboutView.frame;
aboutFrame.origin.x = 104; // new x coordinate
aboutFrame.origin.y = 457; // new y coordinate
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration: 1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
aboutView.frame = aboutFrame;
**[UIView commitAnimations];**

Related

About iOS10 animation

I'm coding a login view, when the keyboard show, background will move the same distance with an animation, but I find a question that I can't understand, when the animation begin, at the top of the background will display a white area, the white are is just the area that will disappear when the animation finished.
Here is my code
- (void)keyboardWillShow:(NSNotification *)notification{
CGRect keyboardBounds;
[[notification.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardBounds];
NSNumber * duration = [notification.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
NSNumber * curve = [notification.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey];
keyboardBounds = [self.view convertRect:keyboardBounds toView:nil];
CGRect viewFrame = self.view.frame;
viewFrame.origin.y = 0 - keyboardBounds.size.height;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:[duration doubleValue]];
[UIView setAnimationCurve:[curve intValue]];
[UIView setAnimationDelegate:self];
self.bgView.frame = viewFrame;
[UIView commitAnimations];
}
Thanks in advance!

Changing UIViews height goes to the bottom but should go up

I want to do a bar-graph animation. Where the bars go up when the view loads. Here is what I do.
CGRect bar1Frame = self.rootView6.bar1.frame;
bar1Frame.size.height = 181;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
self.rootView6.bar1.frame = bar1Frame;
[UIView commitAnimations];
The problem is that the bars height goes to the bottom of the view instead of going to the top.
Anyone can help me?
You need to update the y origin of the bar1Frame as well with
bar1Frame.origin.y = bar1Frame.origin.y - 181;
bar1Frame.size.height = 181;
and apply the animations as you did. Doing so will show your bar above the horizontal line of the graph.
You need to change the y-position of the UIView.
Eg: if you need to change height to 100 then
bar1Frame.origin.y = bar1Frame.origin.y-100;
CGRect bar1Frame = self.rootView6.bar1.frame;
bar1Frame.size.height = 181;
bar1.Frame.origin.y -= bar1Frame.size.height;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
self.rootView6.bar1.frame = bar1Frame;
[UIView commitAnimations];

UIView Animation Mac OSX Effect

I'm animating a small view with popup effect to alert you of an error ... The animation works perfectly but still are not very satisfied because I would like the view does not stop at position (x 25) but I wish they came to ( x 40 ) and then return immediately to ( x 25). In other words I would like to recreate the effect they have on the textfield MontainLion when you are wrong to insert the fields User for access to the operating system ...
I really hope to be able to explain to me , but if I did not succeed please comunicarmelo so that I can explain it better to resolve this question. Thanks to all! Rory .
Below I show you the code to display the pop-up I'm using
- (Void)presentazioneViewTransition
{
CGRect endREct ;
endREct = CGRectMake (25, 160, 270, 90);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.25];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(endRightAnimation)];
self.frame = endREct;
[UIView commitAnimations];
}
You can use the simple block based UIView animation methods like this
-(void)presentazioneViewTransition{
CGRect transitionRect = CGRectMake(40.0f, 160.0f, 270.0f, 90.0f);
CGRect endREct = CGRectMake (25.0f, 160.0f, 270.0f, 90.0f) ;
[UIView animateWithDuration:0.15f
animations:^{
self.frame = transitionRect;
}
completion:^(BOOL finished) {
[UIView animateWithDuration:0.1f
animations:^{
self.frame = endREct;
}];
}];
}

How to reuse this button instead of creating a button

How to reuse this button instead of creating a button
CGRect frame = tenBtn.frame;
CGRect frame1 = reffButton.frame;
frame.origin.x = frame1.origin.x; // new x coordinate
frame.origin.y = frame1.origin.y; // new y coordinate
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration: 3.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
tenBtn.frame = frame;
[UIView animateWithDuration:3.0 animations:^
{
[tenBtn setTransform:CGAffineTransformMakeScale(.4, .4)];
}completion:^(BOOL finished) {
tenBtn.hidden = YES;
}];
[UIView commitAnimations];
i want button(tenBtn) to move their original position or frame instead of creating when i clicked restart button

How to lengthen the UISearchBar in x direction with animation?

I want to lengthen the right search bar 20 px to the left, and shorten left search bar 20 px to the right with animation. How can I do that?
CGRect leftFrame = self.leftSearchBar.frame;
//leftFrame.origin.x = leftFrame.origin.x - 20;
leftFrame.size.width = leftFrame.size.width - 40;
CGRect rightFrame = self.rightSearchBar.frame;
rightFrame.origin.x = rightFrame.origin.x - 40;
rightFrame.size.width = rightFrame.size.width + 40;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:0.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
self.leftSearchBar.frame = leftFrame;
self.rightSearchBar.frame = rightFrame;
[UIView commitAnimations];
It doesn't work. It first resizes views without animation, then moves the right view with animation.
Assuming you've not changed the anchor points, or anything like that, simply expanding the width will make it stretch to the right. Wrap this within a UIView animation block, and it should animate according to the specification within the question, as so:
UISearchBar* searchbar = ...; // However you've created your UISearchBar, we'll refer to it as 'searchbar'
CGRect searchFrame = searchbar.frame;
[UIView animateWithDuration:0.8
delay:0.0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
searchFrame.size.width += 30;
searchbar.frame = searchFrame;
}
completion:nil];
You'll need to make sure the += 30 doesn't get called more than once, as otherwise you'll be expanding by 30 points each time this is called. If you know the size before hand, you could simply substitute it with = size + 30, which is a safer bet incase you call the animation more than once.

Resources