Note that there are some explanatory texts on larger screens.

plurals
  1. POHow I can start an action without clicking to a button?
    primarykey
    data
    text
    <p>I have two UIButtons and I want to click first in the Number1 <code>UIButton</code> and then in the Number 2 <code>UIButton</code>. After clicking the second <code>UIButton</code> I want the two <code>UIButton</code>'s to be rotated automatically. I use <code>CABasicAnimation</code> to rotate them. The two <code>UIButton</code>'s have the same <code>buttonClicked</code> action. The two buttons use different <code>CABasicAnimation</code> methods.</p> <p>I have created a new method in order to rotate it, but when I call it from the <code>button clicked</code> action (same for the two buttons) only the first one is rotated. In order to call the rotate method I use <code>[self rotateButtons];</code></p> <p>The problem is that If I insert a new <code>UIButton</code> and give an <code>IBAction</code> to the new button it's fine. But I don't want a new button in the layer.</p> <p>How I fix <code>rotateButtons</code> so that both buttons <strong>could be rotated simultaneously</strong>?</p> <p>Here is the code:</p> <pre><code>- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag { if ([value isEqualToString:@"SecondImage"]) { UIImageView *myView2=(UIImageView *)[self.view viewWithTag:numberOfCurrentButton+100]; [myView2 setHidden:FALSE]; UIImageView *myView=(UIImageView *)[self.view viewWithTag:numberOfCurrentButton]; [myView setHidden:TRUE]; CALayer *layer2 = myView2.layer; layer2.anchorPoint = CGPointMake(0.5f, 0.5f); CABasicAnimation *animateImage2 = [CABasicAnimation animationWithKeyPath: @"transform"]; CATransform3D transform2 = CATransform3DIdentity; transform2.m34 = 1.0/-900.0; self.view.layer.transform = transform2; layer2.transform = CATransform3DMakeRotation(-M_PI/2, 0.0f, 1.0f, 0.0f); self.view.layer.transform = transform2; transform2 = CATransform3DRotate(transform2, -M_PI, 0.0f, 1.0f, 0.0f); animateImage2.repeatCount = 1.0; animateImage2.toValue = [NSValue valueWithCATransform3D: transform2]; animateImage2.duration = 0.5; animateImage2.fillMode = kCAFillModeForwards; animateImage2.removedOnCompletion = NO; [layer2 addAnimation: animateImage2 forKey: @"halfAnimatedImage"]; return; } } -(void) rotateView1 { UIImageView *firstImage=(UIImageView *)[self.view viewWithTag:numberOfCurrentButton]; CALayer *layer = firstImage.layer; layer.anchorPoint = CGPointMake(0.5f, 0.5f); CABasicAnimation *animateImage = [CABasicAnimation animationWithKeyPath: @"transform"]; CATransform3D transform = CATransform3DIdentity; transform.m34 = 1.0/-900.0; self.view.layer.transform = transform; layer.transform = CATransform3DMakeRotation(M_PI, 0.0f, 1.0f, 0.0f); [animateImage setDelegate:self ]; animateImage.repeatCount = 0.5; animateImage.toValue = [NSValue valueWithCATransform3D: transform]; animateImage.duration = 0.5; animateImage.fillMode = kCAFillModeForwards; animateImage.removedOnCompletion = NO; animateImage.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; [animateImage setValue:@"SecondImage" forKey:@"halfAnimatedImage"]; [layer addAnimation: animateImage forKey: @"halfAnimatedImage"]; } -(void) rotateView2 { UIImageView *firstImage=(UIImageView *)[self.view viewWithTag:numberOfCurrentButton]; CALayer *layer = firstImage.layer; layer.anchorPoint = CGPointMake(0.5f, 0.5f); CABasicAnimation *animateImage = [CABasicAnimation animationWithKeyPath: @"transform"]; CATransform3D transform = CATransform3DIdentity; transform.m34 = 1.0/-900.0; self.view.layer.transform = transform; layer.transform = CATransform3DMakeRotation(M_PI, 0.0f, 1.0f, 0.0f); [animateImage setDelegate:self ]; animateImage.repeatCount = 0.5; animateImage.toValue = [NSValue valueWithCATransform3D: transform]; animateImage.duration = 0.5; animateImage.fillMode = kCAFillModeForwards; animateImage.removedOnCompletion = NO; animateImage.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; [animateImage setValue:@"SecondImage" forKey:@"halfAnimatedImage"]; [layer addAnimation: animateImage forKey: @"halfAnimatedImage"]; } -(IBAction) buttonRefresh:(UIButton *)sender { numberOfCurrentButton=1; [self rotateView1]; numberOfCurrentButton=2; [self rotateView2]; } -(IBAction)buttonClicked:(UIButton *)sender { [self buttonRefresh:sender]; } </code></pre> <p>` </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload