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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:38:04+00:00 2026-06-01T04:38:04+00:00

I’ve been working at this for two days and have not had much luck.

  • 0

I’ve been working at this for two days and have not had much luck. I have a little, tile image that I’m able to drag and drop anywhere on the screen with a touche’s coordinates. My first question is: how can I set the tile images coordinates so that it starts off inside of the green CGRect instead of the top corner screen? In other words, I want to make the green CGRect the image’s default location with affecting the users toch coordinates. My next question is how can I code it to where the only other location on the screen that I can drag and drop the image to, is inside the red CGRect? And if more then half of the image is inside the red CGRect, how can I make it snap to the inside of the Red CGRect if someone lets go of it. If more then half of the image is OUTSIDE of the CGRect, I want to animate it back to it’s default location. If your going to answer please explain your answer in detail because I’m new to objective-c. Here’s a screen shoot of my GUI.

I phone GUI screenshot

Here is my code so far:

DADViewController.h

#import <UIKit/UIKit.h>
#import "DADView.h"
@interface DADViewController : UIViewController
@property(nonatomic, weak)IBOutlet DADView *dadView;
@end

DADViewController.m

#import "DADViewController.h"
@implementation DADViewController
@synthesize dadView = _dadView;
-(void)setDadView:(DADView *)dadView
{
    _dadView = dadView;
    [self.dadView setNeedsDisplay];
}
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [[event allTouches] anyObject];
    CGPoint location = [touch locationInView:touch.view];
    location.x -= 40;
    location.y -= 40;
    self.dadView.thePoint = location;
    [self.dadView setNeedsDisplay];

}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    [self touchesBegan:touches withEvent:event];
}

DADView.h

@interface DADView : UIView
@property(nonatomic) CGPoint thePoint;
@end

DADView.m

#import "DADView.h"
@implementation DADView
@synthesize thePoint = _thePoint;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}
- (void)drawRect:(CGRect)rect
{
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(ctx, 2.0);
    CGContextSetStrokeColorWithColor(ctx, [UIColor redColor].CGColor);
    CGRect rectangle = CGRectMake(120, 70, 70, 70);
    CGContextAddRect(ctx, rectangle);
    CGContextStrokePath(ctx);

    CGContextSetLineWidth(ctx, 2.0);
    CGContextSetStrokeColorWithColor(ctx, [UIColor greenColor].CGColor);
    CGRect rectangle2 = CGRectMake(120, 290, 70, 70);
    CGContextAddRect(ctx, rectangle2);
    CGContextStrokePath(ctx);

    UIImage* pngWord = [UIImage imageNamed:@"wordbutton_01.png"];
    [pngWord drawAtPoint:self.thePoint];
}
@end
  • 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-01T04:38:06+00:00Added an answer on June 1, 2026 at 4:38 am

    To set the view at the beginning:

    CGRect viewFrame = view.frame;
    viewFrame.origin = startingRect.origin;
    view.frame = viewFrame;
    

    view is your image, and startingRect is the rect where you want your image to start, and this code in the awakFromNib or in or when you set the image

    To check if the image is inside of a frame when being dragged:

    -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
        CGFloat middleX = CGRectGetMidX(imageView.frame);
        CGFloat middleY = CGRectGetMidY(imageView.frame);
        if(middleX > rectangle2.origin.x && middleX < CGRectGetMaxX(rectangle2) && middleY > rectangle.origin.y && middleY < CGRectGetMaxY(ractangle2)) {
       // if the imageView is inside of the box
       }
    else imageView.frame = defaultFrame;
    

    imageView is the image that is being moved and rectangle 2 is the frame that you want the imageView in, while default frame is where the image’s frame should be set to if it doesn’t end in the box

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need a function that will clean a strings' special characters. I do NOT
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

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.