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 4033930
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:54:31+00:00 2026-05-20T11:54:31+00:00

I’ve created a puzzle engine for iPad (iOS SDK 4.2) I have a PuzzleViewController

  • 0

I’ve created a puzzle engine for iPad (iOS SDK 4.2)

I have a PuzzleViewController that controls a UIView (rootView) that holds a smaller UIView (puzzleView) and twelve puzzle pieces (PuzzlePieceView class extends UIImageView).

The ideia is very simple. The puzzlePieces are around the puzzleView and are picked and dragged to the puzzleView. When the pieces are picked they double they’re size and are centered to place where the finger is touching.
When they’re dropped in the right place they stay put (they’re removed from rootView and added as subviews to the puzzleView) if they’re drop in the wrong place they return to the original position and size.

Currently I’m overriding touches Began/Moved/Ended/Cancelled in the PuzzlePieceView class so that each PuzzlePiece controls its own movements.

here’s what they do

#pragma mark UIResponder overriding

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"PuzzlePiece touchesBegan");
    if (!isDeployed) {
        if (self.initialSize.width == 0 || self.initialSize.height ==0) { //if there is still no initial size
            self.initialSize = self.frame.size;
        }
        NSLog(@"self.initialLocation.x %f %f", self.initialLocation.x, self.initialLocation.y);
        if (self.initialLocation.x == 0. || self.initialLocation.y == 0.) { //if there is still no initial location
            self.initialLocation = self.center; //record the initial location
        }
        UITouch *touch = [[event allTouches] anyObject];
        self.center = [touch locationInView:self.superview]; //set the center of the view as the point where the finger touched it
        [self.superview bringSubviewToFront:self]; //the piece brings itself as frontMostView so that it is always visible and never behind any other piece while moving
    }
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"PuzzlePiece touchesMoved");
    if (self.frame.size.width == self.initialSize.width) {
        self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.image.size.width, self.image.size.height);
    }
    if (!isDeployed) {
        UITouch *touch = [[event allTouches] anyObject];
        self.center = [touch locationInView:self.superview]; //set the center of the view as the point where the finger moved to
    }
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"PuzzlePiece touchesEnded");
    if (!isDeployed) {
        UITouch *touch = [[event allTouches] anyObject];
        NSLog(@"point %@ x%f y%f", self.puzzleView, [touch locationInView:self.puzzleView].x, [touch locationInView:self.puzzleView].y);
        if (CGRectContainsPoint(self.dropZone,[touch locationInView:self.puzzleView])) {
            [self removeFromSuperview];
            [self.puzzleViewController addPiece:self];
            self.center = self.finalCenter;
            self.isDeployed = YES;
        }
        else {
            [self restoreToInitialSize];
            [self restoreToInitialPosition];
        }
    }

}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"PuzzlePiece touchesCancelled");
    if (!isDeployed) {
        [self restoreToInitialSize];
        [self restoreToInitialPosition];
    } 
}

#pragma mark -

Seemed pretty easy and it was.

I’ve got only one bug left.
When I try to make an horizontal move on any puzzlePiece the touch gets cancelled.
This only happens when the move is started in a fast way. If i touch the piece and wait for a moment (about a second) the pieces move perfectly.
The pieces also move perfectly in the vertical direction.

I’ve tried not changing the puzzlePiece size when the view is first touched bu the bug remains…

  • 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-05-20T11:54:31+00:00Added an answer on May 20, 2026 at 11:54 am

    I found the solution to this.
    One of my team-mates registered a UISwipeGestureRecognizer in the RootView instead of the specific subview were the swipeGesture should be recognized.

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

Sidebar

Related Questions

No related questions found

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.