I have an iPad app and I'm having an issue in my rootViewController. I'm getting the wrong frame for it for some reason. The rotation works fine visually, but when I'm in landscape mode my width and height are reversed. Logging the frame I get the following:
Portrait: self view frame = {{0, 20}, {768, 1004}}
Landscape: self view frame = {{20, 0}, {748, 1024}}
That 20px for the status bar is moving as it should. But those values should be flipped. This view has a UIScrollView as a subview and it's frame is adjusting as it should. Has anyone come across this before?
If the width and height were reversed, the origin would then be wrong... I think this is the expected behaviour, as these coordinates are in the super view's system. What do you get with the bounds rectangle?
Related
I have a UIView and I would like to move it up by 50.
I wrote the following:
NSLog(#"before %#",NSStringFromCGRect(_flixSuggestionsView.frame));
_flixSuggestionsView.frame = CGRectMake(_flixSuggestionsView.frame.origin.x, _flixSuggestionsView.frame.origin.y-45, _flixSuggestionsView.frame.size.width, _flixSuggestionsView.frame.size.height);
NSLog(#"after %#",NSStringFromCGRect(_flixSuggestionsView.frame));
The output is:
before {{0, 175}, {320, 324}}
after {{0, 130}, {320, 324}}
But the UIView stays in the same location.
What am I missing?
If any Autolayout constraints are defined for the view, these determine the view's
position (relative to other UI elements). If you want to control the position "manually",
you have to remove all constraints regarding this view, or switch off Autolayout completely
for the view controller.
How can i disable left or right scrolling in scrollview in iPhone?
can any one give the code..
CGSize scrollableSize = CGSizeMake(320, myScrollableHeight);
[myScrollView setContentSize:scrollableSize];
You have to set the contentSize property of the UIScrollView. Like, if your UIScrollView is 320 pixels wide (the width of the screen), then you could do this
The UIScrollView will then only scroll vertically.
set your scrolview width 320. It will
like
[self.scrolview setFrame:CGRectMake(self.scrolview.frame.origin.x,self.scrolview.frame.origin.y,320,self.scrolview.frame.size.height)];
Within my view I create a scrollview with a width of 320 and a height of 70.
Responding to the user touching a button, I expand the scrollview, so it is 380(h) x 320(w) in size.
The code for this is shown below:
CGRect scrollviewFrame = CGRectMake(0, 30, 320, 380);
[scrollView setFrame:scrollviewFrame];
[self layoutScrollImages:YES];
CGSize srect = CGSizeMake([scrollView bounds].size.width, (kNumImages * (kScrollObjHeight + 10)));
[scrollView setContentSize:srect];
The constants mentioned in the above snippet are defined as:
const CGFloat kScrollObjHeight = 80;
const NSUInteger kNumImages = 100;
As I debug this project, I can see that srect is 320 (w) x 8000 (h) in size; however my issue is the scrollable area (where the user can actually touch to scroll the scrollview) remains the same as when it was it's original size.
I'm obviously missing something, does anyone know what it is?
have created a sample project to illustrate the issue I am having, it is available here: http://dl.dropbox.com/u/9930498/ScrollViewTest.zip
The problem in your sample is you have a very odd structure for loading your views. As such the view you're adding to the DetailScrollView instance is the root view of the DetailScrollView.xib, not the scrollview itself, which I believe is what you were expecting.
Fastest way to fix your problem is to adjust the root view in DetailScrollView.xib to autoresize width and height.
A UIView cannot respond to touches that are outside of the bounds of its superview. In your example, it appears that you expand the scroll view, but the scroll view's parent is still only 100 units high.
You should imagine the scrollView as a window, where by the window I mean the frame of the scrollView, which is also the coordinates that the scrollView detects your touches. By setting the contentView as 320 (w) x 8000 (h) you only change the content of the scroll view, which is the complete area behind that window.
By expanding content view, the scrollView can scroll a broader area, but in order to detect touches in a bigger rect, you should change frame of the scroll view.
Here is an interesting problem. On the iPhone, I have a view set up that has a toolbar on the bottom of the screen. I am currently trying to make this a universal app so that it runs on iPad as well. I would like the toolbar to be at the top of the iPad screen, so in the viewDidLoad method of the specific viewController I have the following code.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
//move the toolbar to the top of the page and move the webview down by the height of the toolbar
CGRect toolBarFrame = self.aToolBar.frame;
CGRect webFrame = self.aWebView.frame;
webFrame.origin.y = toolBarFrame.size.height;
[self.aWebView setFrame:webFrame];
toolBarFrame.origin.y = 0;
[self.aToolBar setFrame:toolBarFrame];
[Utils errorString:[NSString stringWithFormat:#"origen: x=%f y=%f", self.aToolBar.frame.origin.x, self.aToolBar.frame.origin.y]];
[Utils errorString:[NSString stringWithFormat:#"origen: x=%f y=%f", self.aWebView.frame.origin.x, self.aWebView.frame.origin.y]];
}
The problem I am having is that the webView moves down fine, but the toolbar only moves up to about what seems to be the height of a iPhone screen. The call to errorString tells me that the webView's origin is at 0,44 (where it should be) and that the toolbar's origin is at 0,0, but it is actually somewhere in the middle of the screen!
Anybody have a clue what is going on here?
I'd say this is because the frame is being set to the top of an iPhone frame (so 320px from the bottom), and then afterwards the view is being resized to fit the iPad screen. However UIToolbar by default is set to stick to the bottom of the window (fixed bottom margin, and flexible top margin) so it's staying 320px from the bottom.
To fix this try:
[self.aToolbar setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin];
before setting the toolbar's frame (if it doesn't work before setting the frame, try putting it after)
I want a UIScrollView in which i have to paste 25 images of same size(256*256).
The 13th picture should come in the centre,ie, when the app loades.
Then when i swipe right, left, up or down it should scroll as normally.
For doing this what should be the specifications of the UIScrollView,ie,
1.what should be its size
2.ContentViewSize
3.where should be its origin.
If your scrollView is going to be shown full-screen in portrait orientation, you should use the following sizes (assuming you don't hide the status bar):
UIScrollView frame: 320 x 460
contentSize: 8000 x 460 initial
contentOffset: (3840 , 0)