Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9207807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:28:09+00:00 2026-06-18T00:28:09+00:00

I have enabled my Cocoa Touch app to be navigable by swiping left or

  • 0

I have enabled my Cocoa Touch app to be navigable by swiping left or right to alter positions in history. The animation is kind of done like Android’s “card” style. Where swiping to the left (<–) just moves the current screen image out of the way, while showing the previous view beneath it.

This works fine, but when I want to swipe the other way (–>), to go back, I need to get the previous image, and move that over the current view. Now, I had this working if I only store the previous image, but what if I go <– a few times, then I will not have enough images.

So, the solution is obvious, use an NSMutableArray and just throw the latest image at the front of the array, and when you swipe the other way, just use the first image in the array. However, the image never shows when I start the animation. It just shows nothing. Here’s the required methods you should see:

-(void)animateBack {
    CGRect screenRect = [self.view bounds];

    UIImage *screen = [self captureScreen];

    [imageArray insertObject:screen atIndex:0]; //Insert the screenshot at the first index
    imgView = [[UIImageView alloc] initWithFrame:screenRect];
    imgView.image = screen;
    [imgView setHidden:NO];
    NSLog(@"Center of imgView is x = %f, y = %f", imgView.center.x, imgView.center.y);
    CGFloat startPointX = imgView.center.x;
    CGFloat width = screenRect.size.width;
    NSLog(@"Width = %f", width);
    imgView.center = CGPointMake(imgView.center.x, imgView.center.y);

    [self.view addSubview: imgView];
    [self navigateBackInHistory];

    [UIView animateWithDuration:.3 animations:^{
        isSwiping = 1;
        imgView.center = CGPointMake(startPointX - width, imgView.center.y);


    } completion:^(BOOL finished){
        // Your animation is finished
        [self clearImage];
        isSwiping = 0;
    }];
}

-(void)animateForward {
    CGRect screenRect = [self.view bounds];

    //UIImage *screen = [self captureScreen];
    UIImage *screen = [imageArray objectAtIndex:0]; //Get the latest image
    imgView = [[UIImageView alloc] initWithFrame:screenRect];
    imgView.image = screen;
    [imgView setHidden:NO];
    NSLog(@"Center of imgView is x = %f, y = %f", imgView.center.x, imgView.center.y);
    CGFloat startPointX = imgView.center.x;
    CGFloat width = screenRect.size.width;
    NSLog(@"Width = %f", width);
    imgView.center = CGPointMake(imgView.center.x - width, imgView.center.y);

    [self.view addSubview: imgView];

    [UIView animateWithDuration:.3 animations:^{
        isSwiping = 1;
        imgView.center = CGPointMake(startPointX, imgView.center.y);


    } completion:^(BOOL finished){
        // Your animation is finished
        [self navigateForwardInHistory];
        [self clearImage];
        isSwiping = 0;
    }];

}



-(void)clearImage {
    [imgView setHidden:YES];
    imgView.image = nil;
}

-(void)navigateBackInHistory {
    [self saveItems:self];
    [self alterIndexBack];
    item = [[[LEItemStore sharedStore] allItems] objectAtIndex:currentHistoryIndex];
    [self loadItems:self];
}

-(void)navigateForwardInHistory {
    [imageArray removeObjectAtIndex:0]; //Remove the latest image, since we just finished swiping this way.
    [self saveItems:self];
    [self alterIndexForward];
    item = [[[LEItemStore sharedStore] allItems] objectAtIndex:currentHistoryIndex];
    [self loadItems:self];
}

Note that imgView is a class-level UIImageView and imageArray is a class level array.

Any ideas? Thanks.

Edit

Here’s the code at the top of my .m to initalize it. Still does not work.

.....
NSMutableArray *imageArray;

- (void)viewDidLoad
{
    [super viewDidLoad];
    imageArray = [imageArray initWithObjects:nil];
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:28:10+00:00Added an answer on June 18, 2026 at 12:28 am

    It looks like you forgot to create the array. Something like this at the appropriate time would do (assuming ARC):

    imageArray = [NSMutableArray array];
    

    Glad that worked out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Cocoa app with ARC enabled. I am using OS 10.8 and
I have enabled Emulate touch events and can perform normal swipe. Is there a
I have enabled unobtrusive client side validation in my app, and I have (something
I have enabled appstats for my Python App Engine application, and I can access
I have enabled garbage collection in my Cocoa application. Why does my application still
I have a Cocoa app with an NSOutlineView managed by an NSTreeController . In
I have enabled log4net and run my app which is giving an exception. But
I have enabled the push notification for production in my app id , created
I have enabled iAd for an app of mine and I have submitted it
I have a Cocoa app I'm working on and I get a different result

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.