Dilemma with buttons within UIScrollView - iphone

I've got a UIScrollView (scrollView) and a UIImageView (scrollImage). I'm trying to add buttons to a scroll view and have them resize and reposition correctly when I zoom in and out. I had the following code at first to add a button:
[scrollView addSubview:button];
This gave me problems with zooming in and out. The position of the buttons wouldn't stay relative to the image. So i changed it to this:
[scrollImage addSubview:button];
Which made everything zoom in and out nicely, however the buttons have stopped reacting to touches (I assume because they are beneath the UIScrollView).
Is there a way to have both features working correctly?
Thanks
Zac

By default a UIImageView has userInteractionEnabled set to NO. Set it to YES and you should be fine.

try by setting like this,
scrollImage.userInteractionEnabled=YES

Related

Can not swipe when iCarousel contains UITableView as subview

Hi I am using iCarousel in my application, it will have UITableView as subview. When i am trying to swipe or pan to display next or previous item it is not working. I think UITableView's gesture recogonizer disables the iCarousel's gesture recogonizer. There are so many questions like this but i do not see any answer for this. attched is sample image
Please guide me to fix this.
code
_carousel =[[iCarousel alloc]initWithFrame:self.view.frame];
_carousel.type = iCarouselTypeLinear;
_carousel.pagingEnabled = YES;
_carousel.delegate = self;
_carousel.dataSource = self;
[self.view addSubview:_carousel];
It looks like your carousel isn't centered which makes me think that maybe its bounds are wrong.
iCarousel doesn't have clipsToBounds enabled by default, which means that if the bounds are wrong, you will still see your item views, but may not be able to interact with them.
Try enabling clipsToBounds on the carousel, and setting the backgroundColor to something like red, so you can see if the carousel dimensions are correct.
If they aren't you may need to adjust your autoresizing or autolayout constraints.
UPDATE:
This was actually a bug in iCarousel relating to the heuristic it uses to determine if swipe gestures should be intercepted by the carousel. Fixed in beta 7.

How to have two subviews interact with each other?

I have a subview layering problem where I have a rotating arrow and a UIButton. The arrows rotate and the UIButton changes depending on the rotation of the arrows. The problem is that I need to have the UIButton clickable. At the moment the arrows rotate but the UIButton is not touchable. If I try [self.view sendSubviewToBack:wheelControl]; the arrows are sent to the back and are no longer visible.
thanks for any help about how I might fix this.
You need to call
[theView bringSubviewToFront:theButton];
as the last call when laying out your subviews.

Can someone explain if multi-touch zoom is supposed to work for UITextView or UIScrollView

Has anyone gotten multi-touch zoom to work on a textView?
I have searched SO and found no simple way to zoom in on a UITextView or UIScrollView. I was led to this link which says I need to write custom views to overwrite the existing ones in order to be able to zoom in to a textView. I can not believe this and would like someone to please let me know if there is a simple way to zoom in and zoom out using multi-touch on a UITextView or a UIScrollView.
I tried setting the options in the IB to enable multi-touch as well as the max zoom. But this does not work.
Please advise. Thank you.
1 Create a new project with single view (using storyboard & arc)
2 Open Storyboard and add a UIScrollView to your main view controller
3 Set the UIScrollView's delegate to the view controller and create an IBOutlet for the UIScrollView called scrollview
4 Add a UITextView to the scrollview and set an IBOutlet called textview
5 At the end of the ViewDidLoad add the following code:
self.scrollview.minimumZoomScale = 0.5;
self.scrollview.maximumZoomScale = 5.0;
self.textview.text = #"Hellow World!";
6 Add the following method
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return self.textview;
}
7 Run the project and zoom away!
If you want the text to look not render blurry when use the answer at this Blurry UITextField Question
The UIScrollView class provides support for displaying content that is larger than the size of the application’s window. It enables users to scroll within that content by making swiping gestures, and to zoom in and back from portions of the content by making pinching gestures.
By adding your UITextView to a UIScrollView, you can implement muti-touch zoom.
I am resolving to answer this question myself with the assumption that this is not possible at this time. With a textArea I have found no way to zoom in on the text. I have not found any tutorial or example that shows this is possible.

How do I properly handle rotation of a UIScrollView containing UIImageViews?

I'm developing an image viewer, much like the Photos App.
It's a UIScrollView with paging enabled with images loaded from the internet, so I've adapted portions of the LazyTableImages sample. The Scroll View and each ImageView inside of it have all of their autoresize mask flags set.
When I first observed how resizes were happening during rotation, it looked good, but once I started trying to interact with the scroll view, I realized that I also had to programmatically change the size of the contentView. I did that by implementing didRotateFromInterfaceOrientation: in my view controller.
[self.scrollView setContentSize:CGSizeMake(numberOfImages * portraitWidth, [scrollView bounds].size.height)];
With interaction behaving properly, I then discovered that, if I was viewing the second photo and rotated, portions of both the 1st and 2nd photos would be shown on the screen. I needed to change the contentOffset as well.
I've tried to fix this two ways - both by using the scrollRectToVisible:animated: method of UIScrollView, as well as trying to set the contentOffset property directly. And I've experimented by putting this code in implementations of both the "one-step" and "two-step" responses to changes in Orientation. For example:
-(void)didAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
[self.scrollView setContentOffset:CGPointMake(currentlyViewedPhotoIndex * largeImageHeight,0) animated:YES];
In all cases though, it just looks janky as hell. Either I clearly see the scroll happen, or it just jumps. Uuuuuuuuuuugly! Is there a way to do this so that it behaves exactly like the Photos app does?
What I wound up doing instead - just before rotation starts, hide the UIScrollView and create a UIImageView that contains the currently viewed image. Rotate, that image will rotate all nice and pretty, and when rotation completes remove the ImageView and unhide the Scroll View.
Update - if you're reading this today (anytime after iOS 6), use a UIPageViewController and set transitionStyle to UIPageViewControllerTransitionStyleScroll, for crissakes.
I did something slightly different when faced with the same problem. In willRotateToInterfaceOrientation:duration:, I hide all of the UIScrollView's subviews except for the currently displayed subview, and in didRotateFromInterfaceOrientation: I unhide the subviews.

UIScrollView doesn't bounce

I have a UIScrollView contained within a custom UIView with a content size larger than the ScrollView's frame.
I am able to drag scroll as I expect, but the thing doesn't give me the rubber banding effect that you get with the UITableView or UIWebView. It just stops when you get to one of the extremes.
I have set bounce = YES, is there something else I'm supposed to do?
I read the docs, and they say I have to implement the delegate. I did that.
They also say I should change the zoom levels, but I don't want the user to actually be able to zoom so I haven't set these.
For anyone that finds this thread later, if you are subclassing UIView and re-setting the UIScrollView's frame on every layoutSubviews, that is the problem - it cancels the bounce:
http://openradar.appspot.com/8045239
You should do something similar to this:
- (void)layoutSubviews;
{
[super layoutSubviews];
CGRect frame = [self calculateScrollViewFrame];
if (!CGRectEqualToRect(frame, self.scrollView.frame))
self.scrollView.frame = frame;
}
I had the same problem, on a UIScrollView that wasn't all filled up (but I still wanted it to bounce). Just setted:
scroll.alwaysBounceVertical/Horizontal = YES;
And it worked as expected
It turns out that keeping the UIScrollView within my custom UIView was causing the trouble.
Once I switched my custom UIView to instead inherit from UIScrollView, then the bouncing started working.
That is interesting... Is there a lot going on while the user scrolls the scroll view? Maybe that could cause the problem. The iPhone can multitask, but not too much. Can I see your entire code having to do with the scroll view?