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.
Related
I have a UIImageView with a frame of (0, 0, 568, 300) containing a UIImage with a native size of 512x384 pixels. The contentmode is set to Aspect fit.
If the user double-Taps on the view I change the size of the UIImageView with the following code:
self.imageViewerViewController.imageView.frame = CGRectMake(0, -63, 568, 426);
the result is that the right edge of the image is distorted, it does not properly scale to the new size.
Attached is an image with a black and white matrix, the distortion is on the right.
It seems that the right column of pixels is repeated to the right edge of the view.
Can anyone help?
I have changed the creation of the affected UIImageView from a xib file to creating it in code and using the method - (id)initWithFrame:(CGRect)aRect: with the maximum size of the scaled image for aRect. Now the image is properly scaled.
Obviously the UIImageView in the xib file has been inited with a 512x384 pixel frame.
I am developing an application in which i have one image and I need to specify the location in image.But i have left and top values of image only. But we need x,y,width and height values.Then how to find out values from these.So please tell me how to do that.
The left and top values are the x - y positions. The amount of space your image needs to cover the view (frame size) is the width and height. For example, if your image has to cover the full screen of iPhone, you should specify the frame as:
image.frame = CGRectMake(0, 0, 320, 480);
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.
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];