I have a container view which contains an UIScrollView and an UIView, that are at the same level with the same frame and bounds, meaning they are subviews of the container view.
But the UIView is on the top of the UIScrollView. So the problem is that the buttons or gestures on the UIView are responded to my touches, while the UIScrollView is not, either scrolling or zooming.
So how can I make the UIScrollView respond to scrolling and zooming and UIView respond to touches at the same time when these two views are on the same level of the same super view?
UPDATE:
What I'm trying to do is I want to have a player control panel view which contains play/pause button, progress button etc., and behind this panel view there is a player render view which is in charge of rendering the video frames.
And I want to make the render view be able to be zoomed and scrolled, while the control panel view stays still.
The sample code is like this:
#implementation MyVC: UIViewController <UIScrollViewDelegate>
- (void)viewDidLoad
{
UIView *view = [UIView new];
UIScrollView *scrollView = [UIScrollView new];
[self.view addSubview:scrollView];
[self.view addSubview:view];
view.frame = scrollView.frame = self.view.frame;
//zooming and scrolling settings code
//now the problem is that scrollview does not respond to my zooming and scrolling
//while the view does.
}
#end
Maybe you can try this:
[view addGestureRecognizer:scrollView.panGestureRecognizer];
Or add any other UIGestureRecognizer in scrollView.gestureRecognizers to view. But it possibly will cause some issues when zooming. I did not check it. Maybe adding your buttons play/pause to the container view on the level same as scrollView is a better way.
Related
I have taken UIView as subview in View Controller
#property(nonatomic,retain) IBOutlet UIView *subview;
then I am adding custom UIView class in subview like this ,
- (void)showdetail
{
CGRect frameToset = CGRectMake(0, 0, self.subview.frame.size.width,self.subview.frame.size.height) ;
customUIViewPaging *demoView = [[customUIViewPaging alloc] initWithFrame:frameToset];
... // so on
[self.subview addSubview:demoView];
}
In portrait mode it works perfectly but in landscape I am updating the frame like this,
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
[self showdetail];
}
then after it works perfectly in landscape and portrait then I am pushing a another view from this view and landscaping Pushed view after back coming in this view then frame size not getting perfectly (Subview frame not updating the frames while orientation when coming back from another view)
I have tried to put needsUpdateConstraints but it seems not working
[self.subview needsUpdateConstraints];
Check this example
I am not going to Autolayout direction as you want correct frame when view appears ... If you want correct width than call it -(void)viewDidLayoutSubviews{..}
-(void)viewDidLayoutSubviews{
NSLog(#"%f",self.subview.frame.size.width); //here you get correct width
}
now the other problem is you are adding subviews everytime when screen rotates or this method calls .. so better to prevent that by removing previous view...
I have a simple UIScrollView
UIScrollView *mainScrollView = [[UIScrollView alloc] initWithFrame:CGRectZero];
[self.view addSubview:mainScrollView];
[mainScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
When the view is loaded and shown, part of UIScrollView appears under the navigation bar. But after rotation the view is suddenly considers navigation bar and pins the view to its bottom.
How can I make a view consider navigation bar from the beginning?
To start UIScrollView at bottom of UINavigationBar then i would suggest you to set Adjust Scroll View Insets property and setting Extend Edges property as well. do the needful changes of below property as per your requirement.
Ok, I solved this issue.
Problem has been solved by moving creation of scrollView to viewDidLoad method. Somehow, if scrollView is created outside the "load" methods, we can face such kind of problems.
I have been having trouble trying to drag a UIView that has a UIScrollView within it. The UIView drags up from the bottom of the screen, when it has hit the top you can use the UIScrollView inside it. When the user scrolls to the top of the UIScrollView, the UIView should drag down with their finger.
It should work like the Google Maps popup when you click a pin.
Update: I can get the dragging up of the UIView working (touchesMoved) that changes the Y value. The main functionality I am having problems with is the dragging down of the UIView when the user touches inside the UIScrollView. I want the user to still be able to drag the scrollview as normal until it reaches the top at which point the dragging action should then move the parent UIView down off the screen.
Update 2: This is the code you suggested to turn off the user interaction:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
if(scrollView.contentOffset.y<=0){
scrollView.userInteractionEnabled = NO;
}else{
scrollView.userInteractionEnabled = YES;
}
}
Most apps handle this scenario by using the UIScrollViewDelegate method scrollViewDidScroll.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
// check the scrollView.contentOffset.y to see if you
// have reached the top of the scroll view.
}
You can then check the contentOffset and continue with your dragging code the way you want.
Hi I was learning how to use autoresizing and scroll view also and came up with this solution which works, just your feedback would be welcome on my approach if it is ok how it could be improved etc.
I just created a test view controller whose view looks like this.
The grey area is a UIView called mainView and it is subview of view controller's view (and it's longer than view controller's view).
When I changed rotation one would see such thing:
You can see the calculator does not fit on the screen anymore.
So I decided to have a UIScrollView already from start. Add mainView as a subview to it.
Final thing that was remaining, I wanted the frame of the ScrollView to change also when device rotates, so that I could get such effect:
(you see the scroll views width is same as phones).
This is how I implemented all this:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:[self.view bounds]];
[[self view] addSubview:scrollView];
[scrollView addSubview:self.mainView];
[scrollView setContentSize:[mainView bounds].size];
[scrollView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleRightMargin |UIViewAutoresizingFlexibleBottomMargin];
}
Any comments and feedback?
You can use the didRotate methods to position your buttons how you want in the different orientations. There is a good tutorial here: http://www.youtube.com/watch?v=f3yb24f8O1Y&list=PL53038489615793F7
iOS view hierarchies are doing my head in - I want to achieve something that should be basic.
In a UIWebView I want to center a UIActivityIndicatorView with a UILabel below it in the middle of the UIWebView. The activity indicator and the label can be considered as children of another UIView - and it's that parent UIView that needs to be centered in the UIWebView
How does one go about this? How do you get the frame of the parent UIView to be the bounding rect of it's children?
Both views should be sub views of a super view...
UIView *activityView = //the view with the label and activity indicator...
UIView *webView = //the web view...
activityView.center = webView.center;
Done :)