I have a UIScrollView of size 320*460 and with content size 1024*1024.
I can place 25 images of 256*256 in it with the 13th picture shown at the centre of the
screen when it loades with bits of surrounding pictures around it.
When i swipe to any side I want it to appear just like the mapView. With new images
appearing and showing.
How can I do it?
It's very easy & somewhat tricky...
You don't need to define the specific size for the ScrollView.....
Generally we use to define ....as per the Examples of Apple
//#define SCROLLVIEW_CONTENT_HEIGHT 460
//#define SCROLLVIEW_CONTENT_WIDTH 320
which is of no use...if you need the infinite height..
just set the height of the ScrollView dynamically as per the Objects added to the ScrollView....
No need to set the predefined height for this...take the dynamic height....
scrollview.contentSize = CGSizeMake(320, txtView.contentSize.height+450);
CGPoint topOffset = CGPointMake(0,0);
[scrollview setContentOffset:topOffset animated:YES];
Hope this will surely work for you..
Good Luck :)
Checkout the sample code called 'Tiling'. It might be what you're looking for.
When scrolling stops, couldn't you just adjust the bounds so that you are now "re-centered" with your new offset?
Presumably you can't scroll more than so many pixels before your finger hits the edge of the screen, so you only need bounds that a few hundred pixels outside the original center.
Once you have a new center, adjust your bounds accordingly, retiling as necessary.
Related
I've a scroll view which has several UIViews that shows information to the user. This scrollview supports only horizontal scrolling and when user starts scrolling from left to right or vise versa, the center view should be bigger and the previous and next views should be smaller (as shown in the below view).
I'm able to do this by changing the frames of all the views that appear on the scrollviews. But the animation is not smooth. I just want to resize the views while scrolling according to their position. Is there anyway to do this? Any help greatly appreciated.
Well you could look at these links
UIScrollview make the current Image Larger
Or I can provide a better solution to you with iCarousel. Please refer to it and I think this might help you , and its pretty easy to integrate too :)
This might be what you are looking for CGAffineTransformScale. You need to set your UIViews transformation property, for example
CGAffineTransform transformRatio = CGAffineTransformScale(CGAffineTransformIdentity, factorX, factorY);
myView.transform = transformRatio;
factorX and factorY are the values by which to scale your views width and height.
When you view starts scrolling in and out you need to set the corresponding factors.
Well I have an image and I I want that when I touch it and then I move my finger it follows it.but I want that it follows it only vertically like a vertical scrollview(but I don't wanna use a scrollview).How can I do this please. sorry for my english I'm french :/
Why wouldn't you subclass UIScrollView for your view that displays the image? If you do it's pretty simple: define its size so that the horizontal length doesn't exceed the screen length. You'd have to also remember to change this if you allow rotation of the device/view to landscape. Suppose the width of your UIScrollView is 320, you would do this:
CGSize scrollableSize = CGSizeMake(320, myScrollableHeight);
[myScrollView setContentSize:scrollableSize];
Where myScrollableHeight is the full height of the image.
I've never used it but if that doesn't work there is apparently a method you can provide for your UIScrollView class that is called whenever the user attempts to scroll and you can just not adjust the X-coordinate there:
float oldX; // make this ivar in your .h file
- (void)scrollViewDidScroll:(UIScrollView *)aScrollView
{
[aScrollView setContentOffset: CGPointMake(aScrollView.contentOffset.y, oldX)];
}
Take a look at Apple's MoveMe sample. This should give you an idea. If you only want it to move vertically, only change the y value while dragging.
Just adding a panning gesture to the image parent view and moving the image.center (only the y in your case) should be enough. Look at apple documentation for more details
How can I simply let the scrollview bounce, when the content size is smaller than the view's frame and when I drag it?
like iPhone's app search results.
see UIScrollView (paging mode) bounces only when there two or more pages?
you'd better set the property:
scroll.alwaysBounceVertical = YES;
scroll.alwaysBounceHorizontal = YES;
answer myself: the simplest way would be to set the height of the content size to be the height of the frame plus 1. kind of stupid but according to document it only scrolls when size is bigger than frame.
If you prefer .xib just check Bounce Vertically.
Sorry for long winded post.
I am trying to understand UIScrollView and running into very simple problem.
I am creating a scroll view
I am making this view 1.5 size larger then normal size
Using UIScrollView I expect to see some edge elements of view out of bounds, but should be able to pan the view therefore bringing missing elements back to the visible area.
However I am seeing that I can't just pan/scroll view anyway I want, instead view always wants to scroll up, as soon as move away my finger from the screen (touch end event).
I am not handling any touches, etc - I just want to understand why does not scaled view stay put where I scroll it?
CGRect viewFrame = self.view.frame ;
viewFrame.size.width *= 1.5;
viewFrame.size.height *= 1.5;
CGSize mySize = viewFrame.size;
[ ((UIScrollView *) self.view) setContentSize: mySize];
self.view.transform = CGAffineTransformMakeScale(1.5, 1.5);
What I really trying to accomplish is something similar to Number on iPad (the same code will work on iPhone):
There is a view with lots of controls
on it (order entry form)
User can zoom into the entire form so all elements look bigger
user can pan the form therefore bringing various elements into the visible area of the screen.
It seems that UIScrollView can should be able to handle zoom and pan actions (for now I am using Affine Transform to zoom in to the order entry form and iPad)
Thanks
When you transform a view, you transform its internal coordinate system as well. This means that if you scale a view, the view still "thinks" it is the same size it was before the scale because its coordinate units scaled as well.
For example, if you have an image view that has a size of (50,50) and you transform it so that it covers (200,200) on the screen, when you ask the image view its size it will report that its size is still (50,50).
Scrollviews are unusual types of views because they have understand their absolute size relative to physical device screen in order to work properly. When you transform their coordinate system, they lose that connection to the physical device screen and can no longer function properly. This is what you are seeing.
I haven't done this but I'm pretty sure to create the illusion of a zoom in a scrollview, you increase the frame of the scrollview and then transform its subviews (or transform the subviews and then increase the frame of the scrollview to contain the new subview size.) That is the only way to keep the scrollview in sync with the physical device screen.
I have a UIScrollView of size 320*460 and with content size 1024*1024.
I can place 25 images of 256*256 in it with the 13th picture shown at the centre of the
screen when it loades with bits of surrounding pictures around it.
When i swipe to any side I want it to appear just like the mapView. With new images
appearing and showing.
How can I do it?
It's very easy & somewhat tricky...
You don't need to define the specific size for the ScrollView.....
Generally we use to define ....as per the Examples of Apple
//#define SCROLLVIEW_CONTENT_HEIGHT 460
//#define SCROLLVIEW_CONTENT_WIDTH 320
which is of no use...if you need the infinite height..
just set the height of the ScrollView dynamically as per the Objects added to the ScrollView....
No need to set the predefined height for this...take the dynamic height....
scrollview.contentSize = CGSizeMake(320, txtView.contentSize.height+450);
CGPoint topOffset = CGPointMake(0,0);
[scrollview setContentOffset:topOffset animated:YES];
Hope this will surely work for you..
Good Luck :)
Checkout the sample code called 'Tiling'. It might be what you're looking for.
When scrolling stops, couldn't you just adjust the bounds so that you are now "re-centered" with your new offset?
Presumably you can't scroll more than so many pixels before your finger hits the edge of the screen, so you only need bounds that a few hundred pixels outside the original center.
Once you have a new center, adjust your bounds accordingly, retiling as necessary.