我有一个分段控制器,可将两个UIViews xib调用到屏幕上。每个视图的长度因内容而异。由于每个视图的内容是不同的。 UIView在滚动视图中设置。
当使用分段控制器选择选定的UIView时,我将其拉到其他UIView的前面。 问题是当向下滚动时,较长的视图仍然可见。我不知道如何只让滚动向下到已拉到最前面的UIView的底部。
我在选项卡选择的功能中使用simpleViewX.isHidden
或simpleViewY.isHidden
玩耍,但这并不能真正解决问题,因为我仍然可以向下滚动到空白处。
class foodinfo: UIViewController {
var counter = Int()
@IBOutlet var tabs: UISegmentedControl!
@IBOutlet var shiftView: UIView!
@IBOutlet var theTitleLable: UILabel!
var simpleViewX: UIView!
var simpleViewY: UIView!
var theTitleArray = ["Title1","Title2","Title3","Title4","Title5","Title6","Title7"]
override func viewDidLoad() {
//Different subViews for each selection
if counter == 0 {
simpleViewX = SimpleVC0().view
simpleViewY = SimpleVC1().view
shiftView.addSubview(simpleViewY)
shiftView.addSubview(simpleViewX)
}
if counter == 1 {
simpleViewX = SimpleVC2().view
simpleViewY = SimpleVC3().view
shiftView.addSubview(simpleViewY)
shiftView.addSubview(simpleViewX)
}
if counter == 2 {
simpleViewX = SimpleVC4().view
simpleViewY = SimpleVC5().view
shiftView.addSubview(simpleViewY)
shiftView.addSubview(simpleViewX)
}
if counter == 3 {
simpleViewX = SimpleVC6().view
simpleViewY = SimpleVC7().view
shiftView.addSubview(simpleViewY)
shiftView.addSubview(simpleViewX)
}
if counter == 4 {
simpleViewX = SimpleVC8().view
simpleViewY = SimpleVC9().view
shiftView.addSubview(simpleViewY)
shiftView.addSubview(simpleViewX)
}
if counter == 5 {
simpleViewX = SimpleVC10().view
simpleViewY = SimpleVC11().view
shiftView.addSubview(simpleViewY)
shiftView.addSubview(simpleViewX)
}
if counter == 6 {
simpleViewX = SimpleVC12().view
simpleViewY = SimpleVC13().view
shiftView.addSubview(simpleViewY)
shiftView.addSubview(simpleViewX)
}
}
func getTitle() {
theTitleLable.text = theTitleArray[counter]
}
@IBAction func tabselected(_ sender: Any) {
switch (sender as AnyObject).selectedSegmentIndex {
case 0:
shiftView.bringSubviewToFront(simpleViewX)
break
case 1:
shiftView.bringSubviewToFront(simpleViewY)
break
default:
break
}
}
}
答案 0 :(得分:1)
我假设您在滚动视图中将proc CopyBitmap
; BMP graphics are saved upside-down.
; Read the graphic line by line (200 lines in VGA format),
; displaying the lines from bottom to top.
mov ax, 0A000h
mov es, ax
mov cx,200
PrintBMPLoop:
push cx
; di = cx*320, point to the correct screen line
mov di,cx
shl cx,6
shl di,8
add di,cx
; Read one line
mov ah,3fh
mov cx,320
mov dx,offset ScrLine
int 21h
; Copy one line into video memory
cld ; Clear direction flag, for movsb
mov cx,320
mov si,offset ScrLine
rep movsb ; Copy line to the screen
;rep movsb is same as the following code:
;mov es:di, ds:si
;inc si
;inc di
;dec cx
;... loop until cx=0
pop cx
loop PrintBMPLoop
ret
endp CopyBitmap
用作“容器”,并使用加载的shiftView
和simpleViewX
确定simpleViewY
的高度...
不是将简单视图添加为shiftView
的子视图,而是使用垂直shiftView
作为UIStackView
的子视图。将您的简单视图添加为堆栈视图的shiftView
。要“切换”可见的视图,请隐藏另一个视图。堆栈视图会根据剩余的可见视图自动变短或变高,并且,通过将arrangedSubviews
的高度限制为堆栈视图的高度,您的可滚动高度也会自动设置。
如果这样做的话,就不需要shiftView
。