• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Frame Origin Problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Frame Origin Problem


  • Subject: Frame Origin Problem
  • From: Chunk 1978 <email@hidden>
  • Date: Thu, 11 Jun 2009 07:15:58 -0400

while dragging (touching) a view, i'm trying to anchor the view in the
center of the screen and resize the view's width and height based on
the drag, but it's flashes all crazy and i can't figure out why it's
doing so.  i think it has to do with the resetting of the origin
because if i set the origin of the view to a static location in the
(void)touchesMoved method, it works fine, but since the drag resizes
the view, it also (is suppose to) changes it's origin.  i've been in
front of this for 4 hours with no luck.  please help.

-=-=-=-=-=--=-
- (void)viewDidLoad
	{
	CGRect fullScreenRect = [[UIScreen mainScreen] bounds];

	UIView *aView = [[UIView alloc] initWithFrame:fullScreenRect];
	aView.backgroundColor = [UIColor redColor];
	self.background = aView;
	[aView release];

	CGRect aFrame = CGRectMake(0, 0, 50, 50);
	aFrame.origin = CGPointMake(CGRectGetMidX(fullScreenRect) -
CGRectGetMidX(aFrame), CGRectGetMidY(fullScreenRect) -
CGRectGetMidY(aFrame));

	UIView *aBoxView = [[UIView alloc] initWithFrame:aFrame];
	aBoxView.backgroundColor = [UIColor whiteColor];
	self.boxView = aBoxView;
	[aBoxView release];

	[self.view insertSubview:background atIndex:0];
	[self.view insertSubview:boxView atIndex:1];

	[super viewDidLoad];
	}


- (void)dealloc
	{
	[background release];
	[boxView release];
	[super dealloc];
	}


#pragma mark Touch Methods

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
	{
	CGPoint point = [[touches anyObject] locationInView:self.view];
	firstTouchPoint = point;
	}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
	{
	CGRect fullScreenRect = [[UIScreen mainScreen] bounds];

	CGPoint point = [[touches anyObject] locationInView:self.view];
	CGRect boxFrame = boxView.frame;

	boxFrame.size.width += point.x - firstTouchPoint.x;
	boxFrame.size.height += point.y - firstTouchPoint.y;
	boxFrame.origin = CGPointMake(CGRectGetMidX(fullScreenRect) -
CGRectGetMidX(boxFrame), CGRectGetMidY(fullScreenRect) -
CGRectGetMidY(boxFrame));

	[boxView setFrame:boxFrame];
	firstTouchPoint = point;

	NSString *log = [NSString stringWithFormat:@"%f, %f",
boxFrame.origin.x, boxFrame.origin.y];
	NSLog(log);
	}

-=-=-=-=-=-=-=-
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Frame Origin Problem
      • From: Chunk 1978 <email@hidden>
  • Prev by Date: Stepping the event loop?
  • Next by Date: Foundation tool & NSUserDefault
  • Previous by thread: Re: Stepping the event loop?
  • Next by thread: Re: Frame Origin Problem
  • Index(es):
    • Date
    • Thread