使用自动布局移动嵌入在UIScrollView中的UIview [英] Moving a UIview embedded in a UIScrollView, using Auto-layout

查看:80
本文介绍了使用自动布局移动嵌入在UIScrollView中的UIview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我希望在我的ios应用程序中获得的视图的截图.. ViewControlelr嵌入在UIScrollView中。您可以看到,开头有4个重要的UIViews,即View1, View2,FixedView和SEARCH。 UIScrollView必须在FixedView上具有大小高度限制。单击+按钮时将添加一个新视图(View3),使FixedView进一步向下(在此过程中增加UIScrollView的大小)。搜索按钮将固定在屏幕底部。现在有一个 - 按钮可以将ViewController恢复到原始状态。还有一个视图(相同的想法,添加1个视图),我没有为此绘制图片。这是我到目前为止所做的代码。





 _frameForThree = _thirdGroup.frame; 
_frameForFour = _fourthGroup.frame;
_frameForFixed = _fixedGroup.frame;
_frameForFixed.origin.x- = 11;
_frameForButton = _searchButton.frame;
_originalAutoView = _viewForAuto.frame;
_thirdGroup.hidden = true;
_fourthGroup.hidden = true;
_fixedGroup.frame = _frameForThree;
_fixedGroup.frame = CGRectMake(_fixedGroup.frame.origin.x,_fixedGroup.frame.origin.y + 19,_fixedGroup.frame.size.width,_fixedGroup.frame.size.height);







^^在viewDidLoad







  - (IBAction)plusInTwo:(id)sender {
_thirdGroup.hidden = false;
_thirdGroup.frame = _frameForThree;
_fixedGroup.frame = _frameForFour;
_fixedGroup.frame = CGRectMake(_fixedGroup.frame.origin.x,_fixedGroup.frame.origin.y + 15,_fixedGroup.frame.size.width,_fixedGroup.frame.size.height);
_searchButton.frame = CGRectMake(_frameForButton.origin.x,_fixedGroup.frame.origin.y + 160,_frameForButton.size.width,_frameForButton.size.height);
_scrollArea.contentSize = CGSizeMake(_scrollArea.frame.size.width,1.27 * _scrollArea.frame.size.height);
_twoPlus.hidden = true;
_numberOfCities = 3;}


- (IBAction)plusInThree:(id)sender {
_fourthGroup.hidden = false;
_fourthGroup.frame = _frameForFour;
_fixedGroup.frame = _frameForFixed;
_searchButton.frame = _frameForButton;
_scrollArea.contentSize = CGSizeMake(_scrollArea.frame.size.width,1.44 * _scrollArea.frame.size.height);
_threeMinus.hidden = true;
_threePlus.hidden = true;
_numberOfCities = 4;}


- (IBAction)minusInThree:(id)sender {
_thirdGroup.hidden = true;
_fixedGroup.frame = _frameForThree;
_fixedGroup.frame = CGRectMake(_fixedGroup.frame.origin.x,_fixedGroup.frame.origin.y + 19,_fixedGroup.frame.size.width,_fixedGroup.frame.size.height);
_searchButton.frame = CGRectMake(_frameForButton.origin.x,_fixedGroup.frame.origin.y + 160,_frameForButton.size.width,_frameForButton.size.height);
_scrollArea.contentSize = CGSizeMake(_scrollArea.frame.size.width,1.13 * _scrollArea.frame.size.height);
_twoPlus.hidden = false;
_numberOfCities = 2;}



- (IBAction)minusInFour:(id)sender {
_fourthGroup.hidden = true;
_scrollArea.contentSize = CGSizeMake(_scrollArea.frame.size.width,1.27 * _scrollArea.frame.size.height);
_fixedGroup.frame = _frameForFour;
_fixedGroup.frame = CGRectMake(_fixedGroup.frame.origin.x,_fixedGroup.frame.origin.y + 15,_fixedGroup.frame.size.width,_fixedGroup.frame.size.height);
_searchButton.frame = CGRectMake(_frameForButton.origin.x,_fixedGroup.frame.origin.y + 160,_frameForButton.size.width,_frameForButton.size.height);
_threePlus.hidden = false;
_threeMinus.hidden = false;
_numberOfCities = 3;}









thirdGroup 指的是View3。 第四组是指View4(由于它是相同的想法,因此不在我发布的图片中)。 OriginalAutoView和Number ofCities与问题​​无关,因为它是应用程序基本逻辑的一部分,而不是此视图问题。请帮助我解决这个问题并对这个问题提出任何疑问



https://drive.google.com/file/d/0BwmtWeos3VGHbkVneUhxTFIxOVk/view?usp=sharing [ ^ ]

解决方案

如果是关于自动布局问题,尝试使用Masonry库框架..您可以使用

 podfile 

添加第三方库..第三方真的有助于解决任何约束问题。


Here is the screenshot of a view That I hope to get in my ios app.. The ViewControlelr is embedded on a UIScrollView.as you can see, in the beginning there are 4 important UIViews, namely-"View1", "View2","FixedView" and "SEARCH". The UIScrollView must have size height limit at FixedView. When the "+" button is clicked A new View (View3) is to be added, bringing FixedView further down (increasing the size of the UIScrollView in the process). The Search Button is to be pinned at the bottom of the screen. There is a "-" button now that would bring the ViewController back to the original state. There is also one more View (same idea, add 1 more view), I didn't draw a picture for that. Here is the code for what I have done so far.


_frameForThree=_thirdGroup.frame;
_frameForFour=_fourthGroup.frame;
_frameForFixed=_fixedGroup.frame;
_frameForFixed.origin.x-=11;
_frameForButton=_searchButton.frame;
_originalAutoView=_viewForAuto.frame;
_thirdGroup.hidden=true;
_fourthGroup.hidden=true;
_fixedGroup.frame=_frameForThree;
_fixedGroup.frame=CGRectMake(_fixedGroup.frame.origin.x, _fixedGroup.frame.origin.y+19, _fixedGroup.frame.size.width, _fixedGroup.frame.size.height);




^^in viewDidLoad



- (IBAction)plusInTwo:(id)sender {
_thirdGroup.hidden=false;
_thirdGroup.frame=_frameForThree;
_fixedGroup.frame=_frameForFour;
_fixedGroup.frame=CGRectMake(_fixedGroup.frame.origin.x, _fixedGroup.frame.origin.y+15, _fixedGroup.frame.size.width, _fixedGroup.frame.size.height);
_searchButton.frame=CGRectMake(_frameForButton.origin.x, _fixedGroup.frame.origin.y+160, _frameForButton.size.width, _frameForButton.size.height);
_scrollArea.contentSize = CGSizeMake(_scrollArea.frame.size.width,1.27 * _scrollArea.frame.size.height);
_twoPlus.hidden=true;
_numberOfCities=3;}


- (IBAction)plusInThree:(id)sender {
_fourthGroup.hidden=false;
_fourthGroup.frame=_frameForFour;
_fixedGroup.frame=_frameForFixed;
_searchButton.frame=_frameForButton;
_scrollArea.contentSize = CGSizeMake(_scrollArea.frame.size.width,1.44 * _scrollArea.frame.size.height);
_threeMinus.hidden=true;
_threePlus.hidden=true;
_numberOfCities=4;}


- (IBAction)minusInThree:(id)sender {
_thirdGroup.hidden=true;
_fixedGroup.frame=_frameForThree;
_fixedGroup.frame=CGRectMake(_fixedGroup.frame.origin.x, _fixedGroup.frame.origin.y+19, _fixedGroup.frame.size.width, _fixedGroup.frame.size.height);
_searchButton.frame=CGRectMake(_frameForButton.origin.x, _fixedGroup.frame.origin.y+160, _frameForButton.size.width, _frameForButton.size.height);
_scrollArea.contentSize = CGSizeMake(_scrollArea.frame.size.width,1.13* _scrollArea.frame.size.height);
_twoPlus.hidden=false;
_numberOfCities=2;}



- (IBAction)minusInFour:(id)sender {
_fourthGroup.hidden=true;
_scrollArea.contentSize = CGSizeMake(_scrollArea.frame.size.width,1.27* _scrollArea.frame.size.height);
_fixedGroup.frame=_frameForFour;
_fixedGroup.frame=CGRectMake(_fixedGroup.frame.origin.x, _fixedGroup.frame.origin.y+15, _fixedGroup.frame.size.width, _fixedGroup.frame.size.height);
_searchButton.frame=CGRectMake(_frameForButton.origin.x, _fixedGroup.frame.origin.y+160, _frameForButton.size.width, _frameForButton.size.height);
_threePlus.hidden=false;
_threeMinus.hidden=false;
_numberOfCities=3;}





"thirdGroup" refers to View3. "fourthGroup" refers to the View4(that is not in the picture i posted as it is the same idea). OriginalAutoView and number ofCities are irrelevant to the question as it is part of the basic logic of the app and not to this view issue. Please help me with this problem and ask any doubt regarding the question

https://drive.google.com/file/d/0BwmtWeos3VGHbkVneUhxTFIxOVk/view?usp=sharing[^]

解决方案

if it's about auto layout problem, try using Masonry library framework.. you can add the third party library using a

podfile

.. that third party is really helpful for fixing any constraints problem.


这篇关于使用自动布局移动嵌入在UIScrollView中的UIview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆