unclear resize UIWebView behavior - ios

I am trying to resize a UIWebView like this:
CGRect oldFrame = zoomView.frame;
zoomView.layer.anchorPoint = CGPointMake(1, 0.5);
zoomView.frame = oldFrame;
if (oldFrame.size.width == 1024) {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
zoomView.frame = CGRectMake(512, 0, 512, 470);
[UIView commitAnimations];
} else {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
zoomView.frame = CGRectMake(0, 0, 1024, 470);
[UIView commitAnimations];
}
The resize works, but the content of the Webview won't follow the resize. It looks like the content get set to the new bounds first and then the View resizes. In the case from 1024 width to 512, the content get set to 512 width directly and then the view shrinks to its new size and position.
What do I oversee here?

Seems it this is the way how animating size and origin get animated. The scrollview won't get updated during this. Solved it by using an own timer and move the view myself.

Related

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

App slowness after using UIView Animations

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

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.

UILabel always animates to same spot

I have a UILabel called "nameLabel" and I have it inside an animation block so that this happens:
_nameLabel.alpha = 1;
CGAffineTransform translate = CGAffineTransformMakeTranslation(50, 50);
_nameLabel.transform = translate;
I thought that animates the UILabel to the spot I specify but it just animates from the above spot to the place where I have it in the Interface Builder. Any help here?
Can you post the animation block and other associated code? I am not sure what CGAffineTransformMakeTranslation does with the label, but if you want to animate the frame location, you can use this:
CGRect frame = _nameLabel.frame;
frame.origin.y = 100; //Desired height, origin.x can be modified as well.
//You can also change the frame size here but it wont work on UILabels, you will need `CGAffineTransformScale` for that.
[UIView animateWithDuration: 1.5
delay:0.0
options:UIViewAnimationCurveEaseInOut | UIViewAnimationOptionBeginFromCurrentState
animations:^ {
[_nameLabel setFrame:frame];
}
completion:^ (BOOL finished) {
}];
Edit: The other way:
CGRect frame = _nameLabel.frame;
frame.origin.y = 100;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.5];
[_nameLabel setFrame: newFrame];
[UIView commitAnimations];
Current state is probably the current location of the label, try that first but if nothing happens, remove UIViewAnimationOptionBeginFromCurrentState or set the frame of the label to another location before the animation, and move it to its initial (the one in the xib file) position in the animation block, its your call.
Watch out because Autolayout cause a lot of problems.
Try to deselect 'Use Autolayout'
It solves to me all the problems trying to translate objects.

Resources