Retain the resolution of the label after scaling in iphone - iphone

I am having a label in a view.After scaling the view, the label looks little blurred,the resolution is lost.How to retain the resolution after scaling.
Here is my code for scaling
secondView.transform = CGAffineTransformIdentity;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
secondView.transform = CGAffineTransformMakeScale(2 ,2);
[UIView commitAnimations];
[self.view bringSubviewToFront:secondView];

I set the ContentScaleFactor property of the label to retain the resolution of the label after scaling .
[label setContentScaleFactor:2];

Create a label of big size itself, scale down using transformations when you add it to the view.
So at the run time when the view will scaleup the label's resolution will not be lost.
This is one of the approach.
Thanks

Related

Animating UIView frame size change with autoresizing subviews

I have a UIView which contains two subviews. I would like to change the superview's frame size with an animation and have the subviews' sizes change in accordance with their autoresize masks.
[UIView beginAnimations:#"Resize" context:nil];
[UIView setAnimationDuration:1.0];
CGRect frame = self.myView.frame;
frame.size.height += 30.0;
self.myView.frame = frame;
[UIView commitAnimations];
The view self.myView is resized over 1 second as expected, but the subviews are resizing immediately. Does anyone know why this is happening and how I might make the subviews animate their resizing as well?
From my googling around, I think it might have something to with the contentMode property. Unfortunately, I'm not really clear as to what that property does. Any help would be much appreciated.
It would have been hard for someone else to give you the correct answer w/o seeing your code though I would have asked you what you are doing after [UIView commitAnimations]. Nevertheless, glad you figured it out. I suggest you use the block animations. They make this type of mistake much easier to avoid by using a completion block. Example:
[UIView animateWithDuration:1.0
animations:^{
CGRect frame = self.myView.frame;
frame.size.height += 30.0;
self.myView.frame = frame;
}
completion:^(BOOL finished){
// whatever you need to do when animations are complete
}];
OK, so I figured out the issue after reading the answer to the following question: Animating a UIView frame, subview UIScrollView doesn't always animate
I basically was doing some work after I scheduled the animation which was causing -layoutSubviews to be called on each of my subviews which automatically caused those views to be arranged at the end point of the animation. By scheduling my animation after this work was done I was able to solve my problem.

CAAffineTransformationMakeRotation problem

I have a problem with CAAffineTransformationMakeRotation. M trying to rotate a UIView with 22.5 degrees in ViewDidLoad, and after a delay of 1 sec,the View flyin to the screen.
the code is:
-(void)ViewDidiLoad{
imgView1 = [[UIView alloc] initWithFrame:CGRectMake(20,150,.1,400)];
[imgView1 setBackgroundColor:[UIColor blackColor]];
[self.view addSubview:imgView1];
CGAffineTransform trans = CGAffineTransformMakeRotation(3.14159/8);
imgView1.transform = trans;
[self performSelector:#selector(img1_enter) withObject:nil afterDelay:1];
}
-(void)img1_enter{
CGRect frame = [imgView1 frame];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.99];
frame.origin.x = 550;
[UIView commitAnimations];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.99];
[imgView1 setFrame :frame];
[UIView commitAnimations];
}
The problem is that when this view fly's in..its width and height changes. I've tried without rotating the View(i.e without AffineTransformation), it works properly.
Is there any other method to rotate the View??
You could incorporate the already existing transform to preserve the current size respectively aspect ratio:
imgView1.transform = CGAffineTransformConcat(trans, imgView1.transform);
Also the documentation of the UIView class says that the frame property is undefined if the transform is not the identity transform, so you must not use it after you applied a rotation.
The frame-rectangle represents the position and size of the view within the coordinate-system of its superview. The bounds-rectangle represents the inner coordinate-system of the view, so the bounds-rectangle is sort of responsible for the actual pixel-amount (respectively the amount of columns and rows) of the view.
If the contentMode is set to UIViewContentModeRedraw and you alter the frame-rectangle, then the size of the bounds-rectangle automatically gets adjusted that it fits the size of the frame-rectangle and vice-versa, else the bounds-rectangle stays untouched. For rendering the difference between the frame-rectangle and the bounds-rectangle is compensated by an automatically created transform-matrix.
The last two sentences are only true, iff the transform-property of the view is the identity matrix. If it isn't, the frame-property is invalid and you alone are responsible to provide a proper transform from the coordinate-system of the view to the coordinate-system of its super-view. So if you want to apply a rotation, you also have apply a proper translation and scaling to get the view where you want it to be relative to the coordinates of its super-view.
So in your case, you could set the bounds-rectangle to CGRectMake(-width/2, -height/2, width, height) and set its transform to
CGAffineTransformConcat(
CGAffineTransformMakeRotation(angle),
CGAffineTransformMakeTranslation(x, y)
)
, where x and y are the center-coordinates of the view within the coordinate-system of its super-view.

UiView Transition inside UIView

this feels like a beginner question, but since I am not able to get it working in the intended-fashion, I am hoping somewhere out there is able to point me in the right direction.
What I am trying to achive is a transition of a view inside a view.
I fundamentally want to replace a view inside a view with another view(controller?!?) 's content.
lets say, I have an image of a book and I want to do a transition inside the book to another page (going from the calendar-view to the detailed daily view for example). I only want the "book-content"(white content area) to be included in that transition, and not the whole book itself(whole screen).
I can do a transition with the same view, no problem, but I dont get it working trying to replace the view with a completly different view.
It didnt matter having the views in seperate viewcontrollers, or all the views in one viewcontroller, so I were not able to get it working yet, but even worse, I am running out of ideas.
So HELP! If please somebody out there could be so kind and tell me what I am doing wrong.
Suggestions also very much appreciated.
Thanks!!
Tom
Maybe you could hide one view then show the other using a UIView Animations block.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:view1.view cache:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:view2.view cache:YES];
[UIView setAnimationDuration: 1.5];
[UIView commitAnimations];
view1.view.hidden = YES;
view2.view.hidden = NO;
Edit: Is this what you were looking for?
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[view1 viewWillDisappear:YES];
[view2 viewWillAppear:YES];
view1.view.hidden = YES;
view2.view.hidden = NO;
[view1 viewDidDisappear:YES];
[view2 viewDidAppear:YES];
[UIView commitAnimations];
Or, you could use something like this:
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionTransitionFlipFromRight
animations:^{
[view1 removeFromSuperview];
[mySuperview addSubview:view2];
}
completion:nil];
Check out the exchangeSubviewsAtIndex: method in the UIView class. Just set up the 2 views that you want to transition from and to as subviews of another view; then call this method on that parent view.
Suppose you have a view controller with two views, A and B. They have identical frames so they occupy the same space in the controller's view, for your purposes displaying a page of a book. You want to display one and transition to the other.
One way would be to set the alpha property of one to 1.0 (opaque) and the other to 0.0 (transparent). Because this property can be animated you could do a fade from one to the other using a beginAnimations:context/commitAnimations, or use one of the block methods like the docs advise.
Another way would be to animate a change in frame in the two views. Set up the views so that one has a frame such that it is in the right place to display, the other has the same frame but with frame.origin.x equal to frame.size.width - it will be hidden because it is off-screen or hidden behind some other view. Animate the frame in by setting view A's frame.origin.x to -frame.size.width and frame B's frame.origin.x to the display position x origin. Then set (no animation) frame A's frame.origin.x to frame.origin.width again, update its content and you are ready to slide another page in from the right.

UIView Animation iPhone (obtaining information on the frame dynamically)

I have a UIView called goalBar which is being animated by increasing the size of the frame according to a float value called destination:
CGRect goalBarRect = CGRectMake(0, 0, destination, 29);
[UIView beginAnimations:#"goal" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:2.0f];
goalBar.frame = goalBarRect;
[UIView commitAnimations];
The animation works perfectly and the rectangular view increases its width over the course of the animation (from 0 to the value for destination).
However, I wish to be able to extract the values for the frame of the UIView being animated (i.e. goalBar) as the animation takes place. By that I mean that I wish to place the value of the width for the animated frame in a separate UILabel so that the user sees a counter that provides the width of the UIView as it's being animated.
Any help on how to do the above would be gratefully received.
How about observing the frame property of the view. So that you get callbacks when it changes.
See Key-Value Observing.
I've looked into this and it seems that it is not possible to get updates on the state of the components being animated during the UIView animation process.

Animate the enabling of a UIBarButtonItem?

Is there a way to animate enabling or disabling a button? I've tried the following with no success. I'm guessing at this point that the enabled property cannot be animated like opacity can – but I hope I'm wrong.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0f];
theButton.enabled = YES;
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
I can't believe there isn't a setEnabled:(BOOL)enabled animated:(BOOL)animated method.
This is actually really easy. UIView.transitionWithView can take a snapshot of any view and cross-dissolve from the snapshot to the new state of the view. You can use that capability to animate a lot of changes, including enabled.
Just use the View Controller's view as the target view, specify TransitionCrossDissolve, then animate as you would normally.
UIView.transitionWithView(self.view,
duration: 0.5,
options: UIViewAnimationOptions.TransitionCrossDissolve,
animations: { () -> Void in
self.someButton.enabled = !self.someButton.enabled
}, completion:nil)
Animatable properties (through UIView beginAnimations:context:) are: frame, bounds, center, transform, alpha (from Apple docs).
So you've to determine what exactly your animation is (in terms of color/alpha/transform animations) and create manual animation (maybe you'll have to use CAAnimation instead of UIView beginAnimations:context:)
You can break down the enable/disable of a button into a change in opacity between two overlapping images each in one state or the other (i.e. make it look like a fade-in/fade-out). In the animation completion handler you can to do the actual enable/disable toggle.
Here's an idea :)
Within your animation block, Remove the button from view and add it again with disabled state. You can specify what kinda animation you want here..
Set: self.buttonSetEvent.customView.alpha = 0.2;
and try this
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:0.15];
[UIView setAnimationRepeatCount:2];
[UIView setAnimationRepeatAutoreverses:YES];
self.buttonSetEvent.customView.alpha = 1;
[UIView setAnimationDelegate:self];
[UIView commitAnimations];