简体   繁体   中英

IOS Swift changing position within scrollview

I have a ScrollView which contains a view and an image. The views content is variable from 1 to 3 lines of text. the image should be shown right below the view, but I cannot make that happen.

first idea: alter the y position of the

var bannerFrame = image.frame
bannerFrame.origin.y = 50
image.frame = bannerframe

no result. the image stays at its postion, no matter what

second idea: as the image is aligned right below the view, I tried to change the height of the view and naively thought, the image would be aligned. nothing happened as well.

I've also tried to work with "sizeToFit" on the view, no effect either.

What am I missing?

I solved it myself.

namesView is view with dynamic height. The image is aligned below this. Overriding the height constraint of namesView solved the problem:

        namesView.addConstraint(NSLayoutConstraint(item: namesView, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 0, constant: NEWHEIGHT))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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