I have a doubt about to stop animation in UILabel,
I'm using a UIView to animate a UILabel, my code is similar to:
-(void)pickerRowTransformItem:(int)item{
//Get UILabel
UILabel *labelTem = (UILabel *)[self.picker viewWithTag:item];
if (labelTem){
[UIView animateWithDuration: 0.10
delay:0.0
options:UIViewAnimationTransitionNone | UIViewAnimationOptionCurveLinear
animations:^{
labelTem.transform = tr //Scale transform;
labelTem.textColor = color //Change color;
}
completion:^(BOOL finished){
}];
}
}
to stop animation, should I use?
-(void)pickerRowTransformItemStopAnimation:(int)item{
//Get UILabel
UILabel *labelTem = (UILabel *)[self.picker viewWithTag:item];
if (labelTem){
[labelTem.layer removeAllAnimations]; //stop animation??
}
}
or, which is the best way to stop a animation?
thanks!
I think the following article will benefit you. I believe this person solved the same question that you have. Try adding completion:NULL to your code instead of labelTem.layer removeAllAnimations.
How can I stop an UIViewAnimationOptionRepeat UIView Animation?
Related
I have been trying for some time to create a custom segue that does the opposite of the cover vertical (to create a from top to bottom effect animation).I had looked through other questions, google and youtube but cannot get it working.I am completely new to the classes etc. so any help in a step by step guide or video would be so good. I believe that this URL is trying to do something similar to what I want:
http://jrwren.wrenfam.com/blog/2012/02/01/storyboard-custom-segue-for-custom-pushviewcontroller-animation/ , I just cannot get it working.
If any of you know a way to create a segue that is a top to bottom version of the cover vertical segue could you please help me out?
Well, you would want to create a subclass of UIStoryBoardSegue, like the walkthrough shows you, however under the Storyboard class' .m file(implementation) you would want the following code as your -(void)perform: method -
-(void)perform{
UIViewController *sourceViewController = (UIViewController *) self.sourceViewController;
UIViewController *destinationViewController = (UIViewController *) self.destinationViewController;
[sourceViewController.view addSubview:destinationViewController.view];
[destinationViewController.view setFrame:sourceViewController.view.window.frame];
[destinationViewController.view setTransform:CGAffineTransformMakeTranslation(0, -sourceViewController.view.frame.size.height)];
[destinationViewController.view setAlpha:1.0];
[UIView animateWithDuration:0.75
delay:0.0
options:UIViewAnimationOptionTransitionFlipFromTop
animations:^{
[destinationViewController.view setTransform:CGAffineTransformMakeTranslation(0, 0)];
[destinationViewController.view setAlpha:1.0];
}
completion:^(BOOL finished){
[destinationViewController.view removeFromSuperview];
[sourceViewController presentViewController:destinationViewController animated:NO completion:nil];
}];}
Hopefully this is helpful.
Building on #dmason82's answer, translating to Swift, and simplifying a little, this works for me:
class UIStoryboardSegueFromTop: UIStoryboardSegue {
override func perform() {
let src = self.sourceViewController as UIViewController
let dst = self.destinationViewController as UIViewController
src.view.superview?.insertSubview(dst.view, aboveSubview: src.view)
dst.view.transform = CGAffineTransformMakeTranslation(0, -src.view.frame.size.height)
UIView.animateWithDuration(1.0, animations: {
dst.view.transform = CGAffineTransformMakeTranslation(0, 0)
}) { (Finished) in
src.presentViewController(dst, animated: false, completion: nil)
}
}
}
Here is my implementation of an Opposite Cover Vertical Segue using Storyboards
https://github.com/viccarre/OppositeCoverVerticalSegue
Hi I just tried the two other answer but it doesn't work as you ask.
In order to create a custom segue looking the exact reverse of cover vertical (modal segue default) I created this code :
- (void)perform
{
UIViewController *sourceViewController = self.sourceViewController;
UIViewController *destinationViewController = self.destinationViewController;
[sourceViewController presentViewController:destinationViewController animated:NO completion:nil];
[destinationViewController.view addSubview:sourceViewController.view];
[sourceViewController.view setTransform:CGAffineTransformMakeTranslation(0, 0)];
[sourceViewController.view setAlpha:1.0];
[UIView animateWithDuration:0.75
delay:0.0
options:UIViewAnimationOptionTransitionFlipFromBottom
animations:^{
[sourceViewController.view setTransform:CGAffineTransformMakeTranslation(0,destinationViewController.view.frame.size.height)];
[sourceViewController.view setAlpha:1.0];
}
completion:^(BOOL finished){
[sourceViewController.view removeFromSuperview];
}];
}
#end
To complete dmason's answer and have your controller unwind in the opposite direction - going back up from where it came, do this in the presented view controller:
[UIView animateWithDuration:0.75
delay:0.0
options:UIViewAnimationOptionTransitionFlipFromBottom
animations:^{
[self.view setTransform:CGAffineTransformMakeTranslation(0, -self.view.frame.size.height)];
}
completion:^(BOOL finished){
[self dismissViewControllerAnimated:NO completion:nil];
}
];
Bergy's answer didn't work for me.
dmason's answer is great, and if you want to add an unwind segue so your modal animates properly when it's closed, your perform action could look like this (in a new custom segue class)
- (void)perform
{
UIViewController *sourceViewController = self.sourceViewController;
UIViewController *destinationViewController = self.destinationViewController;
[sourceViewController dismissViewControllerAnimated:NO completion:nil];
[destinationViewController.view addSubview:sourceViewController.view];
[UIView animateWithDuration:0.75
animations:^{
sourceViewController.view.center = CGPointMake(sourceViewController.view.center.x, sourceViewController.view.center.y-600);
}
completion:^(BOOL finished){
[sourceViewController.view removeFromSuperview];
}
];
}
I advise you to use the Hero library to achieve this. It adds a lot of animations and transitions, notably between view controllers : https://github.com/lkzhao/Hero/blob/master/README.md
There is an transition called "Cover", and you can choose the direction (left, top, right, bottom)
Hello I am able to fade an image out automatically. How would I manage to fade the image IN automatically.
Here is my code.
.h
#property (assign) IBOutlet UIImageView *cbizFadeImage;
.m
- (void)viewDidLoad {
//Fade Image Out
CGRect aboutNicheImageFrame = cbizFadeImage.frame;
aboutNicheImageFrame.origin.y = self.view.bounds.size.height;
// iOS4+
[UIView animateWithDuration:0.5
delay:2.0
options: UIViewAnimationCurveEaseOut
animations:^{
cbizFadeImage.alpha = 0;
}
completion:^(BOOL finished){
NSLog(#"Done!");
}];
}
Ok I was able to fade an image in by changing the CurveEaseOut to CurveEaseIn. However now I would like to fade the image out. So the image would first ease in then It would then ease out. Would I use an if statement?
I was able to use the UIViewAnimationCurveEaseInOut.
Instead of UIViewAnimationCurveEaseInOut, use this for options:
options:UIViewAnimationOptionCurveEaseOut
I think what your really asking for is UIViewKeyframeAnimationOptionAutoreverse Used like this...
Image.alpha = 0;
[UIView animateKeyframesWithDuration:5.0 delay:0.0 options:UIViewKeyframeAnimationOptionAutoreverse | UIViewKeyframeAnimationOptionRepeat animations:^{
[UIView addKeyframeWithRelativeStartTime:0.9 relativeDuration:0.0 animations:^{
Image.alpha = 1;
}];
[UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.0 animations:^{
Image.alpha = 0;
}];
} completion:nil];
I'm having a little problem. I have an UILabel which have an UILongPressGestureRecognicer. When the UILongPressGestureRecognizer is called my app is supposed to switch to a new view using a flip animation.
This is the code I have used for the GestureRecognizer:
UILongPressGestureRecognizer *labelLongPressRecognizer;
labelLongPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(LoadLabelSettings:)];
labelLongPressRecognizer.numberOfTouchesRequired = 1;
labelLongPressRecognizer.minimumPressDuration = 2.0;
[NewLabel addGestureRecognizer:labelLongPressRecognizer];
and this is the code for the view switching animation:
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:self.view cache:NO];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0];
[self.view addSubview:LabelSettingsViewController.view];
[UIView commitAnimations];
if (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight || self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
LabelSettingsViewController.view.frame = CGRectMake(0, 0, 480, 300);
}
My problem is that when I hold down on my UILabel the switch animation begins, but when I release it repeats the animation again. So basically the animation occur twice and I only want it to take place once.
Any ideas?
Thanks in advance :)
Are you checking the sender state, e.g.,
- (void)LoadLabelSettings:(UILongPressGestureRecognizer *)sender
{
if (sender.state == UIGestureRecognizerStateEnded) // or whatever
// then do the flipping stuff
}
Check out the "Overview" of the "UILongPressGestureRecognizer Class Reference", which talks about the long press being continuous and I presume numerous events could be triggered:
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UILongPressGestureRecognizer_Class/Reference/Reference.html
I have seen some sample code online regarding a simple UIView slide-in or slide-out. It makes sense to have a UIView start with its coordinates off the screen (negative) and then the animation parameter simply changes the UIView's frame. So first question is: does this provide the most obvious method?
However, in my code, the frame origin is not assignable. I get the Xcode error for that line that says as much.
I simply want to do something like this inside an animation:
self.viewPop.frame.origin.y=100;
Any help is appreciated.
UPDATE
I have solved this problem. The technique I discovered is to assign your view's frame to another CGRect, and make changes to that CGRect, then assign it back to the frame:
CGRect frame = self.moveView.frame;
frame.origin.x = newvalue.
[UIView animateWithDuration:2.0 animations:^{
self.moveView.frame = frame;
}];
I have solved this problem. The technique I discovered is to assign your view's frame to another CGRect, and make changes to that CGRect, then assign it back to the frame:
CGRect frame = self.moveView.frame;
frame.origin.x = newvalue.
[UIView animateWithDuration:2.0 animations:^{
self.moveView.frame = frame;
}];
FWIW, it's nice to have a UIView category around for this type of thing:
#interface UIView (JCUtilities)
#property (nonatomic, assign) CGFloat frameX;
-(CGFloat)frameX;
-(void)setFrameX:(CGFloat)newX;
#end
#implementation UIView (JCUtilities)
- (CGFloat)frameX {
return self.frame.origin.x;
}
- (void)setFrameX:(CGFloat)newX {
self.frame = CGRectMake(newX, self.frame.origin.y,
self.frame.size.width, self.frame.size.height);
}
is it possible to create a design something like this?
any help regarding this would be very helpful for me.the functionality i want is to rotate the wheel left-to-right or right to left for selecting time...yellow is selection color and red is shows the remaining time when countdown is running
Use a Gallery view object. Just fill it with the images you want to scroll horizontally.
This would be a good approximation to what you're looking to achieve.
See my video
http://www.youtube.com/watch?v=4acFshAlGJ8
I have use
https://lh3.googleusercontent.com/-WZEDMSmfrK0/TeeD93t8qYI/AAAAAAAAAKw/X9D6jRkLfLk/s800/MUKScale.png
image as Scale in the scrollView this is an incomplete example just to show how can it is achievable.
here is some helpful piece of code,
in this approx everything is static but for the real work one should to work more,
- (void)viewDidLoad {
[super viewDidLoad];
[self.view addSubview:scrollView];
UIImageView *backImgg = [[UIImageView alloc] initWithFrame:CGRectMake(x,y,886,15)];
[backImgg setImage: [UIImage imageNamed:#"MUKScale.png"]];//Image in the link above
[scrollView addSubview:backImgg];
[backImgg release];
[scrollView setContentSize:CGSizeMake(886,15)];
return;
}
NSTimer *timer ;
float timeSet =0 ;
-(IBAction) btnPressed
{
timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:#selector(showTimeInLbl) userInfo:nil repeats:YES];
}
-(void)showTimeInLbl
{
CGRect visibleRect;
visibleRect.origin = scrollView.contentOffset;
visibleRect.size = scrollView.contentSize;
NSLog( #"Visible rect: %#", NSStringFromCGRect(visibleRect) );
float time = visibleRect.origin.x / 8;
timeSet = time;
lblTime.text = [NSString stringWithFormat:#"%f",time];
[UIView animateWithDuration: .1
animations: ^{
[scrollView setContentOffset:CGPointMake(visibleRect.origin.x - 8,0) animated:NO];
}completion: ^(BOOL finished){
}
];
timeSet-=0.1;
lblTime.text = [NSString stringWithFormat:#"%f",timeSet];
if(timeSet<=0)
{
[timer invalidate];
lblTime.text = #"0";
[UIView animateWithDuration: .1
animations: ^{
[scrollView setContentOffset:CGPointMake(0,0) animated:NO];
}completion: ^(BOOL finished){
}
];
}
}
You can use a Never Ended scrollView (For example this you have in it like off paging).
Now by this you will achieve the scale and by using page no or coordinates of the scrollview you can find the scale reading to show on above.
On start count down create animation of UIView contentOffset CGPointMake(10, 100).
for example:
[UIView animateWithDuration: 1.5 /* Give Duration which was also on top */
animations: ^{
[scrollView setContentOffset:CGPointMake(0,0) animated:NO];
}completion: ^(BOOL finished){ }];