Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS - CAKeyFrameAnimation - Not Playing
    primarykey
    data
    text
    <p>I have looked at a few guides for CAKeyFrameAnimation and I am failing to see how to trigger them. The only thing I can think of is that I have to use it as a return, but that doesn't make much sense to me.</p> <p>-H File-</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; #import &lt;QuartzCore/QuartzCore.h&gt; @interface ImageSequenceViewController : UIViewController &lt;UIGestureRecognizerDelegate&gt;{ UISwipeGestureRecognizer *swipeLeftRecognizer; NSMutableArray *myImages; IBOutlet UIImageView *imageView; IBOutlet UIImageView *bView; IBOutlet UISegmentedControl *segmentedControl; } @property (nonatomic, retain) UISwipeGestureRecognizer *swipeLeftRecognizer; @property (nonatomic, retain) UIImageView *imageView; @property (nonatomic, retain) IBOutlet UISegmentedControl *segmentedControl; -(IBAction)takeLeftSwipeRecognitionEnabledFrom:(UISegmentedControl *)aSegmentedControl; -(IBAction)ButtonPressed1: (id)sender; @end </code></pre> <p>-M File-</p> <pre><code>#import "ImageSequenceViewController.h" @implementation ImageSequenceViewController @synthesize swipeLeftRecognizer; @synthesize imageView; @synthesize segmentedControl; /* // The designated initializer. Override to perform setup that is required before the view is loaded. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } */ /* // Implement loadView to create a view hierarchy programmatically, without using a nib. - (void)loadView { } */ //CUSTOM CODE // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. -(void)loadLeft { //aView = [[UIImageView alloc] initWithFrame:self.view.frame]; CALayer *layer = [CALayer layer]; [layer setFrame:CGRectMake(0.0, 0.0, [[self view] frame].size.height, [[self view] frame].size.width)]; myImages = [[NSMutableArray alloc] init]; for(NSUInteger count=0; count&lt;100; count++){ NSString *fileName; if (count &lt; 10) { fileName = [NSString stringWithFormat:@"trailerRotation_000%d", count]; } else if (10 &lt;= count &lt; 100) { fileName = [NSString stringWithFormat:@"trailerRotation_00%d", count]; } else { fileName = [NSString stringWithFormat:@"trailerRotation_0%d", count]; } NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:@"jpg"]; //UIImage *image = [[UIImage alloc] initWithContentsOfFile:fileName]; //[myImages addObject:image]; [myImages addObject:[UIImage imageWithContentsOfFile:path]]; } CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"Contents"]; [anim setDuration:0.10]; [anim setCalculationMode:kCAAnimationDiscrete]; [anim setRepeatCount:1]; [anim setValues:myImages]; [self.view.layer addSublayer:layer]; [layer addAnimation:anim forKey:@"images"]; //aView.animationImages = myImages; //aView.animationDuration = 10.00; //aView.animationRepeatCount = 1; } -(void)loadRight { bView = [[UIImageView alloc] initWithFrame:self.view.frame]; myImages = [[NSMutableArray alloc] init]; for(NSUInteger count=99; count&gt;0; count--){ NSString *countString; if (count &lt; 10) { countString = @"000"; countString = [countString stringByAppendingFormat:@"%d", count]; } else if (10 &lt;= count &lt; 100) { countString = @"00"; countString = [countString stringByAppendingFormat:@"%d", count]; } else if (100 &lt;= count &lt; 1000) { countString = @"00"; countString = [countString stringByAppendingFormat:@"%d", count]; } NSLog(@"%d", count); NSString *fileName = @"trailerRotation_"; fileName = [fileName stringByAppendingFormat:countString]; fileName = [fileName stringByAppendingFormat:@".jpg"]; [myImages addObject:[UIImage imageNamed:fileName]]; } bView.animationImages = myImages; bView.animationDuration = 10.00; bView.animationRepeatCount = 1; } - (void)viewDidLoad { [super viewDidLoad]; imageView = [[UIImageView alloc] initWithFrame:self.view.frame]; [imageView setImage:[UIImage imageNamed:@"trailerRotation_0000.jpg"]]; //[self.view addSubview:imageView]; [self loadLeft]; [self loadRight]; UIGestureRecognizer *recognizer; recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)]; [self.view addGestureRecognizer:recognizer]; [recognizer release]; recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)]; self.swipeLeftRecognizer = (UISwipeGestureRecognizer *) recognizer; swipeLeftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft; if ([segmentedControl selectedSegmentIndex] == 0) { [self.view addGestureRecognizer:swipeLeftRecognizer]; } self.swipeLeftRecognizer = (UISwipeGestureRecognizer *) recognizer; [recognizer release]; } - (void)viewDidUnload { // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; self.segmentedControl = nil; self.swipeLeftRecognizer = nil; self.imageView = nil; } - (BOOL)canBecomeFirstResponder { return YES; } - (void)viewDidAppear:(BOOL)animated { [self becomeFirstResponder]; } -(void)startItLeft { NSLog(@"Left"); //[aView startAnimating]; //[self.view addSubview:aView]; //[aView release]; [bView release]; } -(void)startItRight { NSLog(@"Right"); [bView startAnimating]; [self.view addSubview:bView]; //[aView release]; [bView release]; } //- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event { //} //- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { //} //- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event { //} -(IBAction)ButtonPressed1:(id)sender { NSLog(@"Button"); //[aView stopAnimating]; [bView stopAnimating]; //[self loadLeft]; [self loadRight]; } -(IBAction)takeLeftSwipeRecognitionEnabledFrom:(UISegmentedControl *) aSegmentControl { if ([aSegmentControl selectedSegmentIndex] == 0) { [self.view addGestureRecognizer:swipeLeftRecognizer]; } else { [self.view removeGestureRecognizer:swipeLeftRecognizer]; } } -(void)handleSwipeFrom:(UISwipeGestureRecognizer *) recognizer { //CGPoint location = [recognizer locationInView:self.view]; //[self showImageWithText:@"swipe" atPoint:location]; if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft) { //[self startItLeft]; } else { [self startItRight]; } } //CUSTOM CODE // Override to allow orientations other than the default portrait orientation. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } - (void)dealloc { [super dealloc]; } @end </code></pre> <p>I'm rather new to iOS development so any advice is helpful.</p> <p>Thanks.</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.
    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