when I draw a UIView in landscape mode of ipad , it gives wrong width and wrong height,i have mentioned as follows
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation==UIInterfaceOrientationLandscapeRight);
}
rightView.view.frame = CGRectMake(598, 700, 60, 171);
but width is very high,height is very low…any help please?
When in landscape mode, as the frame is in the coordinates system of its parent view and the parent view has a CGAffineTransform applied (to apply the interface orientation), with and height are inverted.
See this other question that also deals with related issues
YOu may set frame like. it will give you a require result.
CGRectMake(self.view.size.width-426 ,self.view.size.height-100 , self.view.size.width-366, self.view.size.height-497);
just write below line
rightView.view.frame = CGRectMake(598, 700, 171, 60);
Related
i have created a view in textfield should characters method like this. when i change my view from portrait to landscape my view width is not changing.
viewForautoCompleteTableView = [[UIView alloc]initWithFrame:CGRectMake(30, 120, 212, 100)];
viewForautoCompleteTableView.autoresizingMask=UIViewAutoresizingFlexibleWidth;
[self.view addSubview:viewForautoCompleteTableView];
viewForautoCompleteTableView.layer.borderWidth=1;
viewForautoCompleteTableView.layer.borderColor=[UIColor grayColor].CGColor;
thank you
Note that :
On Rotation, self.view.frame size does not change but self.view.bounds does , and bounds represent correct values with respect to current Interface Orientation.
There are two points that you have to check
. Is your view( viewForautoCompleteTableView) allocated ?
. If you want to change the width while rotation then you have to change the width of your view in didRotateFromInterfaceOrientation:UIInterfaceOrientation)fromInterfaceOrientation method
-(void)didRotateFromInterfaceOrientation: (UIInterfaceOrientation)fromInterfaceOrientation{
// put the condition to check for your orientation type i.e. portrait or landscape
CGSize newSize= CGSizeMake(newWidth,height); // setting new width here
CGRect viewFrame=viewForautoCompleteTableView.frame;
viewFrame. size = newSize;
viewForautoCompleteTableView.frame=textFrame; // provide some animation if required
}
Note:- Please make sure your view is allocated
I'm using a UIProgressView in my application, which is working great right now. But I want to make it larger (height-wise) and color it a different color.
I'm looking to use PDColoredProgressView for the color, and alter the -(void)drawRect:(CGRect)rect method to change the height, however I can't decide where I would actually alter the height. Any suggestions on what to change?
So it turns out you can resize it like any other view.
[coloredProgressView setFrame:CGRectMake(0, 0, 300, 25)];
Setting the frame side didn't seem to work for me. Setting the transform to a CGAffineTransformMakeScale() can scale it up - not sure if that causes any other problems though.
To change the height of progressView try below code: ( works with Swift 5 )
progressView.transform = CGAffineTransform(scaleX: 1, y: 4) // y present the wanted height
and 1 present the current width, so if you change it to 3 then it will mean current width x 2
I've managed to manually detect rotation and set my own rotation effects between two UIViewControllers. When in the first, rotating to landscape prompts the second to be pushed on with a manual animation. The status bar moves to the correct orientation. However, the view loaded by the second UIViewController is not in the position I expected it. Instead there is margin on the left where the status bar previously was and margin/space at the bottom that I was expecting to be filled by the view.
(Click to enlarge. The orange box is simply to reference where 0,0 is in the rotated UIView, CustomView)
The code I'm using in my view controller to do the rotation is:
-(void)loadView {
CustomView *customView = [[CustomView alloc] initWithFrame:CGRectMake(0, 20, 480, 300)];
self.view = customView;
CGAffineTransform rotate = CGAffineTransformMakeRotation(degreesToRadian(90));
[self.view setTransform:rotate];
[customView release];
}
Any help would be much appreciated!
EDIT Managed to solve after a variety of trial and error approaches - answer provided below. Perhaps there's a more elegant/obvious solution though - if so feel free to provide!
try these on the viewcontrollers. Solved the 20 pixel(status bar height) clip issue when I was getting fullscreen subviews to show up.
[viewcontroller1.view setCenter:CGPointMake(viewcontroller1.view.center.x, viewcontroller1.view.center.y-20)];
and/or
[viewcontroller2.view setCenter:CGPointMake(viewcontroller2.view.center.x-20, viewcontroller2.view.center.y)];
I managed to solve this by setting the View's bounds after the transformation:
self.view.bounds = CGRectMake(20, -20, 480, 300);
I'm relatively new to objective-c...I'm using the iphone 3.0 SDK
I have a UIView, which is a subview, that I want to resize under certain circumstances.
The way I do it is within a controller class.
for example,
CGSize el = CGSizeMake(30, 40);
[self.subview setSize:el];
the above code does work, but the compiler gives a warning: 'UIView' may not respond to 'setSize:'
At some level, "if it ain't broke, I don't want to fix it", but I'm a little worried that I'm doing something wrong.
Any ideas as to why I'm getting the warning and how I can fix it?
TIA
That probably means that setSize for UIView is implmented but it is not shown in the header file that is imported into the project. That makes it an undocumented API, ie one day it could change and break your code :)
And sure enough if you go to the documentation of UIView you will find no refrence to the size property. So I would avoid it.
What you should use instead is the frame property
CGSize el = CGSizeMake(30, 40);
CGRect bounds = CGself.subview.bounds;
bounds.size = el;
CGself.subview.bounds = bounds;
Give that a shot.
The right thing to do here is use something else instead of the non-public size property. But for the sake of discussion: If you wanted to get rid of the warning, you can declare that you know about the size property somewhere at the top of your implementation file:
#import "MyClass.h"
#interface UIView (private)
- (void) setSize: (CGSize) newSize;
#end
#implementation MyClass
…
#end
The compiler will stop complaining.
Here is a closer explanation using the "frame" property for "myView":
[self.myView.frame = CGRectMake(x, y, width, height)];
Where:
x, coordinate FOR the top left corner of your view having as
reference the top left corner of its parents "x" coordinate.
y, same
as x but y axis
width, horizontal size of the frame
height, vertical size of the frame
i.E. You have a view which fits to the screen bounds, so its coordinate (0,0) will be the same as your device screen top left corner.
if you want to add a subview barely smaller that the screen size and center it horizontally and vertically, here is the set up:
[self.myView.frame = CGRMake ( 20 , 20 , self.view.frame.size.width-40, self.view.frame.size.height-40);
This example sets the frame inside the view and centered. Note that we subtract 40 to the width corresponding to: 20 left side, 20 right side, and so the same for vertical adjustments.
This code will also work in portrait and landscape mode.
I'm using a UIWebView with text in it. When the iPhone is rotated to landscape, text doesn't fill the now wider UIWebView width. I'm using P (paragraph) tags, which should not affect content filling landscape's width. The line breaks that are visible in portrait remain the same in landscape. In Interface Builder, I haven't changed anything. In the IB Inspector, Web View Size has all solid bars under AutoSizing, which means it should fill to the landscape width right?
Here is a tweak though not a good thing to do, and something should be handled by apple itself
As you've noticed that things workfine when WebView is initialized in portrait and then you turn it to landscape. So.. what you can do is always initialize your webview with portrait bounds, add a selector which calls back after 2~3 seconds and sets the frame of webView according to your requirement.
Now as the contents started loading when the frame size of your webview were according to portrait (say 320,460) so converting your webview to landscape will automatically adjust your web view if you have this line in your code
[webViewObjet_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
Below is the snippet of code
- (id) initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame])
{
webViewObjet_ = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
.....
}
}
- (void) webViewDidStartLoad:(UIWebView *)webView
{
.....
[self performSelector:#selector(chuss) withObject:nil afterDelay:3];
// call the function chuss after 3 second
}
- (void) chuss
{
webViewObjet_.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
[webViewObjet setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
}
Now tried around with the same problem, finally did it after looking detailed at "WhichWayIsUp"-Sample from Apple.
To keep it short:
1) Disable in the View Inspector the |--| and <-->
2) `switch the View Mode from the Webview to "Aspect Fill"
Et voila ;)
Keep the vibes,
Maniac
I have the same problem. Reloading does not work, the only thing that seems to help a bit is to add the following line to the code:
self.view.autoresizingMask =
UIViewAutoresizingFlexibleWidth;
(I place it in the willAnimateFirstHalfOfRotationToInterfaceOrientation function)
It still keeps a small white margin at the right, but its far better than the default. Note: you should apply this on the self.view and not on the UIWebView instance, that won't work.
Waiting for a solution from Apple..
Pieter
This will sound strange, but it works:
If the UIWebView is inside a UINavigationController, it will all work just fine. I had the same problem, so I just wrapped it up in a UINavigationController and the problem was gone.
For some reason, UINavigationController makes rotations work like a charm.