Questions tagged [cgrect]

CGRect is a structure from the ApplicationServices framework used with Apple's OSX and iOS operating systems. This structure is used to represent the origin and size of a rectangle.

CGRect is a structure that contains the location and dimensions of a rectangle.

Fields

  • origin: A point that specifies the coordinates of the rectangle’s origin.
  • size: A size that specifies the height and width of the rectangle.
716 questions
4
votes
1 answer

Swift 3.0 converting error fix

I have a swift 2.2 project. Now I upgraded it to Swift 3.0 but I have some errors. open var gridClippingRect: CGRect { var contentRect = viewPortHandler?.contentRect ?? CGRect.zero contentRect.insetInPlace(dx: 0.0, dy:…
W.venus
  • 470
  • 2
  • 6
  • 19
4
votes
2 answers

CGRect vs constraints in programmatic GUI Design?

We use CGRect inside a frame specifying the width, height and the exact coordination of the rectangle (shape). Do I need to specify constrains for the UI elements one by one as well? If yes, why do I need to? How about device rotation (portrait vs.…
Danial Kosarifa
  • 1,044
  • 4
  • 18
  • 51
4
votes
1 answer

UIView convertRect: - finding subview position two views deep

In the pictures below, each rectangle is a UIView. View A has a weak reference to view C. View A creates view D and needs to add it as a subview to view C so that view A is covered completely. I therefore need to get the position of view A relative…
mashers
  • 1,009
  • 7
  • 22
4
votes
2 answers

Accessing CGRect values directly vs normalizing them in Swift - Objective-C rules still valid?

This question is inspired by Andrew Carter's comment on a previous question about the new CGSize initializer in Swift. The Apple Docs for CGGeometry say: ... your applications should avoid directly reading and writing the data stored in the …
JAL
  • 41,701
  • 23
  • 172
  • 300
4
votes
3 answers

Aspect fit programmatically in iOS?

I want to insert one view into another with aspect fit option. But I can't just set contentMode for some reasons. Could you provide a solution via resizing of the inner CGRect according to the outer CGRect? And yes, there are a lot of similar…
Vyachaslav Gerchicov
  • 2,317
  • 3
  • 23
  • 49
4
votes
1 answer

Draw a rectangle the starting point and follow my movement to end the gesture in Swift

I asked a question on stackoverflow and received a perfect answer to my case. To get the start point and end point of UIPanGestureRecognizer, use the code: var view = UIView() func panGestureMoveAround(gesture: UIPanGestureRecognizer) { var…
James
  • 1,167
  • 1
  • 13
  • 37
4
votes
1 answer

Changing a views bounds affect the frame

I'm trying to understand how a view responds to its bounds being changed. If I change the bounds origin of a view, will it change the frame origin accordingly? E.g. UIView *greenView = [[UIView alloc] initWithFrame:CGRectMake(150, 150, 150,…
Smashkon
  • 115
  • 1
  • 7
4
votes
3 answers

Swift - Add Color to CGrect

I'm currently Adding a rectangle to an image in case it's not squared "filling" the remaining space, making it square. The idea is that this is a cheap approach (in terms of time required to "force" an image to be squared). As you can see in the…
Waclock
  • 1,686
  • 19
  • 37
4
votes
1 answer

Swift SpriteKit edgeLoopFromRect Issue

The following code recognizes the bottom and top edges of the scene and the ball bounces off as expected. However, the left and right edges of the scene are breached all the time. The ball goes off screen and then eventually returns back if enough…
GusGus
  • 230
  • 6
  • 16
4
votes
1 answer

SpriteKit -- Change SKShapeNode Size

I have a SKShapeNode created by shapeNodeWithRect: cornerRadius:. This rounded rect is a child of an SKEffectNode so I can set shouldRasterize = YES. I'd like to change the width of this node based on the user's touch. i.e. As they move their finger…
rizzes
  • 1,532
  • 20
  • 33
4
votes
2 answers

Make view cover full screen using CGRectMake

I'm creating a view (using card.io), and I want the view to cover the full screen. Its only covering about 2/3rds of the screen atm. Heres the code: CardIOView *cardIOView = [[CardIOView alloc] initWithFrame:CGRectMake(0, 0,…
spogebob92
  • 1,474
  • 4
  • 23
  • 32
4
votes
2 answers

Convert CGPoint from CGRect to other CGRect

I have placed one label on view and view's frame is CGRectMake(0,0,270,203). Now I have to take screen shot of view with CGRectMake(0,0,800,600). So I have to convert label from old rect to new rect. here is code which I used to take screen…
Nirmalsinh Rathod
  • 5,079
  • 4
  • 26
  • 56
4
votes
5 answers

Objective-C generating a random point which lies in given cgrect

my requirement is generating a random point in a given area, i.e i have an Cg Rectangle of some space and I need to generate a random point in this rectangle .. how can I proceed in this scenario?
4
votes
3 answers

How to check if an id points to a CGRect?

Supposing we have: id value = [self valueForKey:@"frame"]; BOOL valueIsCGRect = ???; How can I decide? Should I cast id to something?
Geri Borbás
  • 15,810
  • 18
  • 109
  • 172
4
votes
2 answers

Know the intersection point of two CGRect

I'm programming a game, and i need to detect intersections between two CGRects. To do this, i've no problem. I do like this : CGRect rect1 = CGRectMake (x1, y1, a1, b1); CGRect rect2 = CGRectMake (x2, y2, a2, b2); if (CGRectIntersectsRect(rect1,…
user2057209
  • 345
  • 1
  • 6
  • 19