I have a UIImageView as subview in my scrollView.
I want to be able to pan up/down on UIImage to adjust the color of the UIImage.
Also I want to be able to pan/zoom around the image(that's why I implemented scrollView).
I have an adjustColor IBAction UIButton which adds the UIPanGestureRecogniser as target and executes the function below:
func panned(gesture: UIGestureRecognizer){
...
}
My problem is that the adjustColor button is ignored by scrollView's scroll behaviour.
If I delete the scrollview and add the UIImage, the adjustColor button activates the color adjustment function and the gestures work perfectly.
On the other hand, if I have the scrollview and the image as subviewimage, my adjustColor button has no functionality.
Any help would be appreciated.
Thank you.
Make sure to connect the UIGestureRecognizer IBOutlet with scrollview.
Related
I created a UIStackView with a UIImageView and a UIButton. The text inside of the UIButton won't show. I can tell that autolayout works because the background and the selection of my UIButton both work properly.
The title always disappears when I have the constraints on. I set the image to 0/0/0/0 without margins and aligned the button to the image's edges.
Has anyone run into this or knows how to fix it?
At the end I simply used a UIView. I don't know what made me use the UIStackView but I guess it's not made for overlaying objects.
I have a UIButton underneath a (transparent) UIView. The UIView above has a UISwipeGestureRecognizer added to it, and that is its only purpose - to detect certain swipe gestures. I want all other touches to be ignored by that UIView, and passed to other views (such as my UIButton underneath). Currently, the UIView above seems to be detecting the tap (for example), doing nothing (as it should be), and not letting the UIButton underneath get a chance to respond.
I would prefer not to implement my own swipe recognizer, if possible. Any solutions / advice? I basically just want to know how to tell a UIView to pay attention to only a certain type of added gesture recognizer, and ignore (and thus let through to views behind) all other touches.
Have you set:
mySwipeGesture.cancelsTouchesInView = NO;
to allow the touches to be sent to the view hierarchy as well as the gesture?
Additionally, ensure that the view on top is:
theTransparentView.opaque = NO;
theTransparentView.userInteractionEnabled = YES;
I've had pretty good success attaching gestures to the parent view without needing to create a transparent subview on top for the gesture. Are you sure you need to do that?
I must have just been in a funk yesterday - I woke up with a simple solution today. Add the UISwipeGesture to a view which is a superview to both the UIView and the UIButton. Then, when processing those swipes, figure out where the swipe originated, and whether that point is in the frame of where I used to have the UIView. (As I mentioned, the only reason for the existence of the UIView was to define a target area for these swipe gestures.)
Can't you put your button on top of the view and add gesture recognisers to that button too?
In the end, your UIButton inherits form UIView via UIControl. Therefore there is practically nothing that you could do with a view but not with a button.
In my case, I fixed it by not using a button, but rather a UITapGestureRecognizer. My pan gesture recognizer was added to the background view, and the tap gesture was added to a view above it.
I want to create a big UIScrollView, its contentView should contain more than 30 UIButton. Positions of these UIButton are not rectiligne and cannot be create 'programmaticaly' so I've placed all these UIButton on a UIView manually. I zoom/dezoom and scroll all over my UIScrollView fine BUT here is my problem : UIButton created offscreen is not accessible, I mean I can't click them (only UIButton created in the CGRect(0.f, 0.f, 320.f, 480.f) can be click.
Any suggestion ?
Create a view, put a scrollView inside that view, and place your buttons on the scrollView. While adding buttons and moving them around, be certain that they're always inside the scrollView by looking at the object hierarchy in interface builder.
You can slide the scrollView around as you place things, no need to zoom. As long as your buttons are children of your scrollView it should work fine.
I have a Hierarchy like this: UIScrollView -> UIView -> UIButton
I would like to click the UIButton but it appears the ScrollView is eating up all the events. How can an event be passed down to the UIButton?
I had the exact same issue. What solves the problem is to remove the UIView layer. Build you hierarchy like that UIScrollView -> UIButton.
I put the code from UIView in a subclass of UIButton.
in the same case - when i scroll 1 page down, buttons are not response. buttons above, witch i see after viewDidLoad() are works fine.
try to set userInteractionEnabled = YES for your UIView
I have built a view for an iPhone app in Interface Builder. It is a UIScrollview with a UIView and a UIButton on the UIView. The only code I have is setting the scroll view's contentSize to 320x550 in the viewDidLoad method of the xib's File Owner class. When the button is within the normal view area (320x480) the button responds as normal, but if is placed outside of those boundaries in Interface Builder the button will not respond when I scroll to it and click the button.
What am I missing? I figure it might be something I need to set on the UIView. But I am not sure what that is.
Your UIButton won't response even it's visible because it's not in the boundary of parent view. You can see object outside the boundary of its parent view because it's a default behavior of UIView to draw all subview (clipsToBounds = NO)
To see the truth, try this code.
UIView *yourUIView = ...
yourUIView.clipsToBounds = YES;
yourUIView.backgroundColor = [UIColor cyanColor];
You will no longer see your UIButton.
To fix this, enlarge your UIView.
I had the same problem as the person who posted the question. Thanks to the first answer, I had a hint as to what to do. I increased the height of the view by adjusting the frame. This, apparently must be done in code. Once this was done, however, the toolbar at the bottom was no longer visible. So before I adjust the height of the view, I grab the position of the tool bar. Then after adjusting the height of the view, I reset the position of the tool bar. Now all is good.