User Interaction enabled No Only to the parent - ios

I have one scroll view (UserInteractionEnabled = No) with one image view as its subview.
I am assigning tap gesture to imageview but it is not working even if imageview is UserInteractionEnabled because Its parent (ScrollView) is not.
How can I resolve this conflict.

There is no reason to disable user interaction on a scroll view. If you want to block the scrolling, disable it using the scrollEnabled property.

Don't set scroll view (UserInteractionEnabled = No) because it will set to all its subViews.
hope it will work.

Related

UIMenuController not showing when UICollectionViewCell's subView has userInteraction Enabled

Basically I have an imageView inside cell whose isUserInteractionEnabled is set to true as it has a UITapGestureRecognizer. Now the problem is when I long press the cell outside the imageView area it shows the menu but when I long the imageView itself the menu isn't shown. I didn't understand the behaviour.
I also noticed that even if I remove UITapGestureRecognizer, it still doesn't work. So it has something to do with isUserInteractionEnabled property.
Just disable the user interaction on the image view, because it blocks the interaction on the cell.
imageView.isUserInteractionEnabled = false

UITableView cancels UITapGesture

uitableviewdidselect cancel outs tap gesture action
there is an UIImageView in cell.contentView and there is a tap gesture to enlarge the image the control is not going to the Tap Gesture action its passing to the tableview didselect delegate ? I am using UITableView class for my table already did userInteractionEnabled=YES & cancelsTouchesInView = NO
Make sure you set
tapGestureRecognizer.cancelsTouchesInView = NO;
It won't work because table view can't take two user interactions at a time. First it will give priority to didSelectRowAtIndexPath. You need to disable user interaction on cells. So that tap gesture will be called. Make sure that user interaction enabled for imageView.

How to prevent iOS from resizing your UIViewController's view after return from background

I have a UIViewController that displays a form with several text fields. In order to prevent the text fields from getting blocked by the keyboard, I resize the controller's view when the keyboard appears and disappears.
However, when the keyboard is up, the user presses the home button, and then returns to the app, the controller's view will be resized again to the size it was before the keyboard was up and the keyboard will still be showing.
What's causing my controller's view to be resized on return from background, and how can I prevent it?
Maybe you need to nest a UIView,for example
_backgroundView = [UIView new];
_backgroundView.backgroundColor = [UIColor whiteColor];
_backgroundView.frame = CGRectZero;
[self.view addSubview:_backgroundView];
[_backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.mas_equalTo(self.view);
make.height.mas_equalTo(self.view.mas_height);
}];
then you need add your custom UIView to this backgroundView.
as you said,UIViewController's view will be resized after return from background. so you can nest a UIView of the same size as self.view,and add your custom UIView to this UIView.
In order to prevent the text fields from getting blocked by the keyboard, you can resize this backgroundView when the keyboard appears and disappears. and this time when you click the home button to enter the background or return from background,self.view won't be resized and backgroundView won't be resized too.
Although it is a bit of a hassle, this will solve your problem and will not affect the user experience anymore. And if you have a better solution, please let me know
It sounds like you are setting the frame and not using autolayout. When the view reappears viewDidLayoutSubviews gets called and your frame gets recalculated obliterating your previous change. You can either:
1) Move your frame to viewDidLayoutSubviews and change its size only if the keyboard is showing.
2) Use autolayout and simply pull up your bottom constraint .constant by an amount equal to your keyboard height.
In both cases you should call layoutIfNeeded to trigger autolayout/viewDidLayoutSubviews when the keyboard appears/disappears. This behavior is a good example of why you should not manipulate your frames outside of viewDidLayoutSubviews except for transitory animations.

UIScrollView is moving up if I hide the NavigationBar and the ToolBar

I have a problem, I created a zoomable UIImageView with a UIScrollview, everything works perfect, exept the UIImageView is not in the center anymore and every time I hide the Tool- and NavigationBar the UIImageView/UIScrollView is moving up.
I already set the autoresizingMask:
scrollView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
scrollView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin;
but it won't work, can someone please help me?
I had the same problem with iOS 7, and read I had to set
self.automaticallyAdjustsScrollViewInsets = NO;
for the view controller, but it did not work for me. After I have released I had to put it in viewDidLoad method of the parent view controller of the view controller.
Just like #Mert answered, you can either set it in code self.automaticallyAdjustsScrollViewInsets = NO; or you can set this in storyboard, in the scroll view in one of the inspectors you can un-check the checkbox that automatically adjusts the scroll view content.
EDIT
The checkbox is in the attributes inspector of the UIScrollView, it's called Autoresize Subviews under drawing section.
Btw, this behaviour only happens in iOs7, because of the transparent UINavigationBar thing.

How to handle different scrollView for orientation change in iPad?

I have a scroll view with 2 different subviews for two different orientation.
In portait mode, it shows a table view and in portait it shows the UIImageView.
I want to know the ideal way to handle the orientation.
I am having glitches with my current way of handling
1.Load a view,and add scrollview as a subview to the root view.
2.Change orientation,
3.Change the frame and contents of the scrollview.
4.Add this modified scrollview as subview again.
But, every time I change orientation,the new view gets added on top of the previous one.
If you want to have two different views for different orientations, you need to switch them while orientation is changing.
When you go from portrait to landscape, you have to remove UIImageView and add scrollview (and vice versa)
[myImageView removeFromSuperview];
[self.view addSubview:scrollView];
You can also check if view doesn't have a superview to be sure that you have to add it:
if(scrollView.superview == nil)
[self.view addSubview:scrollView];
As you have already added scrollView as subView so you do not need to add it as subView again.
Just change the frame and contentSize of scrollView.
for Views do as
[scrollView.subView removeFromSuperView]
[scrollView addSubView:view1]; // or add view2

Resources