How can I make scrolling image up impossible ? UIImage embed in UIScroll? - ios

I have an image, embed in UIScroll. I don't want this image be scrolled upwards. Is it possible to implement such a thing?
P.S : OK,guys. I'v just made an uiimage behind my scroll view,that has the same color, as top part of an upper uiimageview.

use UIScrollView Delegate methods
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
if(scrollView.contentOffset.y<0)
scrollView.contentOffset =CGPointMake(0, 0);
}

Only if the image is allowed to stand and the content can go through behind it, place the image directly on the ViewController or the parent view where is the scrollview is stored.

Related

iPhone: UITableview background image stretch/pull/scroll up beyond the view bounds

I have a very specific requirement to fulfil.
Lets say this is my original background image (on the right).
This is how my image should be on the screen by default.
And this is how it should be when I do a "pull down" gesture on the UITableView.
I want to set an image (shown above) as a view's background. A UITableView to be specific.
NOTE: Image size is more than the view size.
When I try to pull down the view beyond the bounds of the view, the image should continue to show up and should not break. With the current implementation the image from the bottom part shows up.
Any ideas how I can achieve this? Pardon me if the solution is obvious.
You can do this by only one line of code
[yourView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"YourBGImgName.png"]]];
OR Alternately
put one UIScrollView and set it's background color with above way and you can find your background repeating when you scrolling your scrollView.
Set the top part as the background for a UITableViewHeaderFooterView in the header and do the same for the footer. Then set a negative inset for your tableView.
Something like
[self.tableView setContentInset:(UIEdgeInsets){-headerHeight, 0, -footerHeight, 0}];

UIScrollView, sliding, zooming

I have an app which has a uiscrollview, which in turn has two uiimageviews.
The scrollview works fine in sliding between both imageviews, by making the content size twice the width. like so
[self.scrollView setContentSize:CGSizeMake(self.scrollView.frame.size.width * 2, self.scrollView.frame.size.height)];
Now the client wants the user to be able to zoom into any image in those two images. He does not want another modal view with the selected picture zoomed in, but rather on the same uiscrollview he wants this to happen. Is this doable? or a good Idea?
The problem I am having is that when I implement the zooming logic ( implementing the delegate
UIScrollViewDelegate
the moment I set the value of
self.scrollView.zoomScale
I end up calling this method
- (UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return [self getCurrentVisibleImage];
}
And with that happening, I end up with the UIscrollview that after zooming back to the normal size of the image, the scrollview simply doesn't slide left or right?
Any help is appreciated.
Answer was simple, I was manipulating contentsize and not setting it properly. that fixed it.

How to add a UIImage to a UIScrollView without breaking the scrolling function?

I have a UIScrollView filling my entire view, which was placed using Interface Bilder. I also placed numerous buttons in my scrollable area, all of which works great.
However, I would like to insert a large UIImage to fill my view as well. When I add the UIImage, the view is no longer scrollable. At first I thought the UIImage might be 'blocking' the UIScrollView, so I arranged it to be sent to back, but it didn't help. Does anyone know how to get my UIImage and UIScrollView to play nice?
Any suggestions are appreciated.
Just use
imageView.userInteractionEnabled = YES;
Image views by default do not have this option set to yes, and they capture all touch events - keeping the scroll view from ever seeing it.
Since you are using the interface builder there might be two reasons for not scrolled:
The UIScrollView size is bigger than the UIImage Size, in this case It will not be scrolled.
UIImage is not added to the UIScrollView content size.
Try this:
[myScrollView setContentSize:CGSizeMake(4500, 320)];
[myScrollView setScrollEnabled:YES];

Resize content of UIScrollView when zooming

I know there is many topics for this subject but I didn't found a good solution for my problem.
I have a UIScrollView with an image and other components added as subviews.
I just want to know the good way to resize the components into in real time when I zoom.
- (void)scrollViewDidZoom:(UIScrollView *)scrollView {
// Resizing image and other components
}
EDIT : I would like the impression that the components inside the scroll view keep the same size when I zoom. I don't want to they become bigger or smaller during zooming.
EDIT : Here is the hierarchy of my UIViewController
View
ScrollView
Main view
Image view
Drawing view (UIView with components like UILabel, other UIViews, etc...)
Thanks a lot !
I would leave the scale of UIScrollView as it is and reach the goal with the help of subview (adjusting its size, not scrollView's), where I would place all the subviews and the images you work with.
So it would be something like:
yourView.transform = CATransform3DMakeScale(newScale, newScale, 1.0);
where yourView is the main (only) subview of scrollView. Then I would recalculate the size of the yourView with new scale and set it to scrollView's contentSize parameter so that you could actually scroll the enlarged content, not only see it truncated.
The only thing is that in this case you should use the callback other than scrollViewDidZoom: I guess.
P.S. Changing UIView's transform parameter you don't need to bother about subviews' scale: CoreAnimation does everything for you.

draw in a sub view added programmatically?

I have a UIScrollView added programmatically to a UIView.
I want to draw few images to the UIScrollView itself.
I know how to draw in the main view using:
[image drawInRect....];
but I just can not understand how to do it inside of a sub view?
i fill that I don't truly understand what is the context and how do i reach it?
thanks for any help.
shani
If you are asking how to add an image to a uiscrollview which has been added programatically then it is simple.
Add the image to a UIImageView then add that Imageview to the scroll view using addSubview: method.
[scrollView addSubview:imageView];
Well if any one wants to know -
the solution is to draw the images to the layer of the UIScrollView.
you can not draw to the view itself without sub classing it.

Resources