简体   繁体   English

带有UIView的UIScrollView(Swift)

[英]UIScrollView with UIView (Swift)

I have implemented a UIScrollView with a UIView which I add when viewDidLoad() to the UIScrollView which is set to the UIViewControllers view. 我已经实现了带有UIView的UIScrollView,我将viewDidLoad()添加到设置为UIViewControllers视图的UIScrollView时将其添加。 When I do this how ever the frame of the UIView with the setTranslatesAutoresizingMaskIntoConstraints(false) gets set to -101.0. 当我这样做时,带有setTranslatesAutoresizingMaskIntoConstraints(false)的UIView框架将如何设置为-101.0。 This does not happen to another view that is displayed differently,but only happens to this view which is designed the same, and displayed with pushViewController from the navigationController. 这不会发生在显示不同的另一个视图上,而只会发生在设计相同的视图上,并与navigationController中的pushViewController一起显示。

The constraints are setup from the NIB/XIB files and I am confused why this is occurring. 这些约束是从NIB / XIB文件设置的,我对此感到困惑。

Another thing to note is that, when this happens, no matter where I try and change the frame of the UIView, it has no affect. 要注意的另一件事是,当发生这种情况时,无论我在哪里尝试更改UIView的框架,它都没有影响。

EDIT: CODE for viewDidLoad(): 编辑:viewDidLoad()的代码:

override func viewDidLoad(){

        // call the super implementation
        super.viewDidLoad();

        // load our scrollview from our nib file
        customScrollView = CustomScrollView.loadFromNib();
        // set the resizeing mask to fill screen
        customScrollView!.autoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;

        // load our uiview from our nib file
        containerView = ContainerView.loadFromNib();
        // we handle the constraint changes
        containerView!.setTranslatesAutoresizingMaskIntoConstraints(false);
        customScrollView!.addSubview(containerView!);

        // intialize our refresh control
        refreshControl = UIRefreshControl();
        refreshControl!.tintColor = UIColor.whiteColor();
        refreshControl!.addTarget(self, action: "onRefresh", forControlEvents: UIControlEvents.ValueChanged);
        containerView!.addSubview(refreshControl!);

        // add the view to our controller here
        view = customScrollView!;



    }

The answer ended up being a custom tableview. 答案最终是一个自定义表格视图。 If anyone else is having this problem, I highly recommend ditching UIScrollView, because it is an utter disappointment from apple. 如果还有其他人遇到此问题,我强烈建议您放弃UIScrollView,因为这对苹果完全是失望的。 The documentation is poor, and there are technical issues with it known to be true. 该文档很差,并且存在一些已知的技术问题。 There are also technical document notes for some issues on the class for anyone who is trying to do something with the class, be sure to read those. 对于尝试在课堂上做某事的任何人,对于课堂上的某些问题,也有技术文档说明,请务必阅读这些内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM