I'm looking to find out the "lower limit" of a frame. The frame in question is a UITextView that resizes based on the size of the content e.g.
CGRect frame = mainTextBox.frame;
frame.size.height = mainTextBox.contentSize.height;
mainTextBox.frame = frame;
This works fine but it is the last item on a scrollView. So what I want to do is program the scroll view to only be as long as nessisary e.g.
[scrollView setContentSize:CGSizeMake(320,1850)]
What I want to do is make the 1850 the right size so that the scrollView finishes just below the mainTextBox.
Is there anyway to get a return as to the distance of the bottom of the frame to the top of the view?
Just add the y coordinate of the origin point (upper left corner of the view) to the height.
CGFloat lowerBound = mainTextBox.frame.origin.y + mainTextBox.frame.size.height;
would CGRectGetMaxY(mainTextBox.frame); work for your needs?
Related
As you can see in the attached image if I keep scrolling past the last object in my scrollview I can keep scrolling and then see the background. Is there a way to limit this in xcode so you can't scroll past the last object in the scroll view?
I'm new to xcode and did try researching this issue though I believe my terminology is impacting this.
Thanks
you will need to set the scrollView.contentSize size so that it fits around all your objects in the scroll view. if you have a way to determine which object is the lowest then you can use its origin + height to determine the height of the content size.
float maxHeight = 0;
for(UIView *v in [scrollView subviews]){
if(v.frame.origin.x + v.frame.size.height > maxHeight)
maxHeight = v.frame.origin.x + v.frame.size.height;
}
self.scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, maxHeight+5);
Goal : How we can find the position of subView in a View. I wants to find out the upper left (x,y)position of my scrollBar in a View, I am also using navigation Bar in my Application does it effect on the positioning of subViews from the Top?
I know how to find the height and width of subview like
CGSize viewSize = scrollView.frame.size;
height=viewSize.height;
width=viewSize.width;
What you're looking for is probably:
CGPoint viewPosition = scrollView.frame.origin;
x=viewPosition.x;
y=viewPosition.y;
But if you're looking to translate to another view's coordinate system, you could use:
- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view
And pass it the point and view you wish to translate.
To get the x and y use origin
CGPoint point = scrollView.frame.origin;
float x = point.x;
float y = point.y;
You can use this one too...
CGRect rect = [scrollBar frame];
float origineFromX = rect.origin.x;
float origineFromY = rect.origin.y;
may this will help you ...
If you put navigation bar in the view, the position of the scrollview has to be shifted downwards to align properly in the view. The origin(top left position) of the scrollview will be different with and without the Navigation bar.
If you are using a fullscreen scrollview, you have to reduce the height of the scrollview to accomodate the navigation bar.
I have a uiview subclass that i want to expand evenly. I mean I want the origin point of the view to be in the center, and have the width and height expand the same amount. Right now the origin point is in the top left, (0,0), and it expands down to the right. How would I go about doing this?
When you change the width and height of the frame, also change the x and y position of the frame by half those amounts.
For example, if your frame is currently (40, 60, 100, 200) and you want it to be wider by 20 and higher by 30, make it (30, 45, 120, 230).
I suggest, if I understand you problem that you get the size of the superview in which the view is located. Let this view be view. Then, let your view be myView.
So all you have to do is the following :
Take half of the size of the screen for width and height values, and to position the origin of your view.
UIView view = myView.superview;
if (nil != view) {
// Make sure your view won't extend by itself with this
myView.autoresizingMask = UIViewAutoresizingNone;
// Get The size of the parent view
CGSize size = view.bounds.size;
// Set the new frame of your view
myView.frame = CGRectMake(size.width/2.0f,
size.height/2.0f,
size.width/2.0f,
size.width/2.0f);
}
And now your view is positioned correctly
I add few labels in UIScrollView and I want when I scroll, the the middle label font size can become bigger. And the previous middle label font size shrinks to smaller. And the change happens gradually. Like below. Label 1 move to left shrink smaller and label 2 move to middle becomes bigger. All labels in a UIScroll view.
I tried some, like when scroll I tried zoom scroll page, seems complex than I thought...
Anyone has good idea? Thanks!
Pretty simple really. Just stick a UIScrollViewDelegate to the scrollview and do something like this..
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
for (int i = 0; i < [scrollView.subviews count]; i++) {
UIView *v = [scrollView.subviews objectAtIndex:i];
float position = v.center.x - scrollView.contentOffset.x;
float offset = 2.0 - (abs(scrollView.center.x - position) * 1.0) / scrollView.center.x;
v.transform = CGAffineTransformIdentity;
v.transform = CGAffineTransformScale(v.transform, offset, offset);
}
}
But, if you aren't impressed by the affine transform, you could still scale the rect using the offset factor and set the UILabel to adjustsFontSizeToFitWidth... and you are done!
Just make sure there is enough space! Else it could get out of hand very easily.
Assumptions :
There are no other views in the scrollview apart from these labels.
Its required to work just horizontally.
It could be done with CoreAnimation. You have to keep the index of the main label (that one in the center), and after scrolling is done or when scrolling starts (use some proper for you method in UIScrollViewDelegate) and simply shrink side labels by animation.
Just make the size of the font bigger (with an animation block) when it is the middle one, and smaller when it is not.
You can add a category to UILabel with -(BOOL)isMiddle and set it to true/false.
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.