I have an UIView which is drawn on screen with frame (0, 0, 60, 60). All I want is if I change frame to (0, 0, 30, 30) I want the view to be drawn only in it's bounds. How can I clear this frame overlap? I tried - setNeedsDisplay on this view but it seems it redraws only new frame and overlap remains.
I am not entirely sure if I got your question right but it sounds like a bounds-clipping issue.
You may want to experiment with the UIView property clipsToBounds on the parent (super-) view.
Related
I'm running into a weird issue with my code and I hope someone else has better ideas on how to handle this.
**Summary of what I want to achieve: **
I have an editor that looks like this:
On the right side I have an inspector panel where I can manually change the frame of the currently selected view (which sits inside another NSView that's the document view of an NSScrollView).
**Summary of implementation: **
The main view inside the NSScrollView doesn't directly use autolayout, because I need to be able to set the frame manually, I leave the translatesAutoresizingMaskIntoConstraints property to true (default value) for all the subviews inside the NSScrollView. So I end up with constraints automatically created when I set the frame.
The problem:
When I set the frame, to let's say (1, 0, 100, 100) for some reason the autolayout engine will take in account the magnification value of the NSScrollView and will readjust the frame, so the final frame might end up looking like (1.74, 0, 100, 100). While I do understand this, the question is, can I disable this behavior? Is it possible to have frame value increments of 1.0 while making sure Autolayout doesn't screw the final frame regardless of the NSScrollView magnification value?
Thank you!
Autolayout views inside a magnified NSScrollView can give very strange values at times, and I haven't really figured out when and why.
I have approached a similar problem by adjusting the views' position manually according to magnification of superview, or by subclassing them and writing a method for them to take the magnification into account.
So, for example:
CGFloat factor = 1 / magnification;
element.frame = NSRectMake(x * factor, y * factor, ...);
Hope this helps.
Same question as https://stackoverflow.com/questions/3100878/ipad-frame-programmatically-doesnt-match-with-ib but no-one answered!
I created a UITableCell layout in IB, copied done the measurements of the UILabel frame and used them to programmatically resize the frame.
But the Y coordinate is out by about 13 pixels - WHY?
Frame in IB x:176 y:16
Frame in code to match X:176.0f, y:3.0f
Check your autoresizing masks and Origin positions.
Im making a simple application to learn getsure recognizers.. I have created four views in my window but when i load the application, the size is completely different to how i had arranged them before.. any ideas why or how i can fix this?
i am importing some co-ordinates in my .h file for pinching.. could this be why?
thanks
Make sure you are setting the views' frames correctly. For example, if you want your view to be 100 pixels wide, 50 pixels tall, and be in the top-left corner of the window, you'd write the following:
myView.frame = CGRectMake(0, 0, 100, 50);
If you wanted to push that view over 10 pixels to the right and 15 pixels down (but with the same dimensions), you'd write the following instead:
myView.frame = CGRectMake(10, 15, 100, 50);
For more information on view frames, read through all the attributes in the "Configuring the Bounds and Frame Rectangles" section on Apple's UIView Class Reference.
I got a subclass of UIView in which I draw an NSString object using the drawInRect:withFont:lineBreakMode:alignment: method.
Unfortunately, when I change the orientation of the device, say from portrait into landscape mode, the text doesn't get redrawn correctly but gets scaled and distorted against my intentions.
How can I solve this problem?
This is part of how Core Animation animates transitions. A snapshot of your view is taken, and then stretched/moved into the new location.
There are a number of ways you can tackle this. First of all you can try this:
self.contentMode = UIViewContentModeRedraw;
This might be all you need and will tell Core Animation to redraw your contents instead of using a snapshot. If you still have issues, you can try defining a "stretchable" region that is stretched instead of your text.
For example, if you know you have a vertical slice of your view where there is never any text, you can define the content stretch to be in that little section and any stretching only occurs there, hopefully keeping your text intact.
CGFloat stretchStartX = 25.0f;
CGFloat stretchEndX = 30.0f;
/* Content stretch values are from 0.0-1.0, as a percentage of the view bounds */
self.contentStretch = CGRectMake(stretchStartX / self.bounds.size.width,
0.0f,
stretchEndX / self.bounds.size.width,
1.0f);
This causes the your view to be stretched only between x values 25 and 30.
For some strange reason, UITableView resizes my cells to 320 width no matter how I set the frame for the UITableView object.
Even if I go in later and resize the cell back to 250, UITableView seems to resize it again to 320 some time.
Is there some property or method that must be set / called additionally to get that right?
However, I can add my contents in a way that it looks like 250 width, but my whole layouting code is a big mess since I can't rely on the cell frame width which is "wrong". Also it seems like a big waste of memory since the bitmaps in the layer trees are nonsenseless 320 width instead of 250, even though the frame of the UITableView is not 320 width.
Try this:
MyTable = [[UITableView alloc] initWithFrame:CGRectMake(0.0, 5.0, 220.0, 385.0) style:UITableViewStyleGrouped];