gpt4 book ai didi

ios - 滑动菜单 - 从右向左移动并向后移动

转载 作者:行者123 更新时间:2023-11-30 12:54:59 26 4
gpt4 key购买 nike

当我点击屏幕菜单时,我有幻灯片菜单,菜单从右到左出现。点击按钮从左向右后退,如何编写代码?

我的幻灯片菜单:

enter image description here

我的代码:

private void UpdateTableViewPosition(CGPoint positon)
{
// set the position of the button based on the provided argument
_buttonToggleVisibility.Frame = new CoreGraphics.CGRect(positon.X , _buttonToggleVisibility.Frame.Y, _buttonToggleVisibility.Frame.Width, _buttonToggleVisibility.Frame.Height);

// TODO:
// if button is outside of the screen
// move it back into the screen

// then move tableview so it is right aligned of the button
_tableView.Frame = new CoreGraphics.CGRect(_buttonToggleVisibility.Frame.Right, _tableView.Frame.Y, _tableView.Frame.Width, _tableView.Frame.Height);
}

public override void TouchesEnded(NSSet touches, UIEvent evt)
{
base.TouchesEnded(touches, evt);

UITouch touch = (UITouch)touches.AnyObject;

_moving = false;

// TODO: fix so that only the button is clickable
// if the touch clicked the button
// open (or close) the view with the following animation code
UIView.Animate(0.9f, () =>
{
// TODO: this animation code is incorrect. Currently it moves the view 100px relatively to the
// current position, but it should rather either set the button to the left corner or the right
// corner at fixed positions
UpdateTableViewPosition(new CGPoint(_buttonToggleVisibility.Frame.X - _buttonToggleVisibility.Frame.Left, 0));

}, null);
}

public override void TouchesCancelled(NSSet touches, UIEvent evt)
{
base.TouchesCancelled(touches, evt);

_moving = false;
}

public override void TouchesBegan(Foundation.NSSet touches, UIEvent evt)
{
base.TouchesBegan(touches, evt);

UITouch touch = (UITouch)touches.AnyObject;

CoreGraphics.CGPoint pos = touch.LocationInView(this);

if (pos.X > _buttonToggleVisibility.Frame.X && pos.X < _buttonToggleVisibility.Frame.Right && pos.Y > _buttonToggleVisibility.Frame.Y && pos.Y < _buttonToggleVisibility.Frame.Bottom)
{
// did click on the view
_moving = true;
}

_buttonToggleVisibility.TouchUpInside += (sender, e) =>
{

};
}
}

最佳答案

我使用 AutoLayout 和 UIView 动画来上下移动控件 View 。 (想象一下键盘,但具有更大的灵 active 。)该板有一个“完成”按钮,可以动画地将板(及其 subview )移出 View 。

由于我有一系列板,因此这里有额外的代码来处理标签属性。这是我找到要使用的板的地方。

关键是:

  • (1) 更改 heightAnchor(或者在您的情况下更改 widthAnchor)
  • (2) 通过调用父 View 的layoutIfNeeded进行动画

..

private var boardIn:[NSLayoutConstraint] = []
private var boardOut:[NSLayoutConstraint] = []
private var tabBoards:[TabBoard] = []

public func createControlBoard(
_ tag:Int
) -> ControlBoard {
let newBoard = ControlBoard(tag)
boardOut.append(newBoard.heightAnchor.constraint(equalToConstant: 100))
boardIn.append(newBoard.heightAnchor.constraint(equalToConstant: 0))
newBoard.doneButton.addTarget(self, action: #selector(hideTabBoard), for: .touchUpInside)
tabBoards.append(newBoard)
return newBoard
}

public func showTabBoard(_ tag:Int) {
for i in 0...tabBoards.count-1 {
NSLayoutConstraint.deactivate([boardOut[i]])
NSLayoutConstraint.activate([boardIn[i]])
tabBoards[i].makeControlsHidden(true)
}
NSLayoutConstraint.deactivate([boardIn[tag-1]])
NSLayoutConstraint.activate([boardOut[tag-1]])
tabBoards[tag-1].makeControlsHidden(false)
UIView.animate(withDuration: 0.3) { self.superview?.layoutIfNeeded() }
}

public func hideTabBoard(_ tag:Int) {
NSLayoutConstraint.deactivate([boardOut[tag-1]])
NSLayoutConstraint.activate([boardIn[tag-1]])
tabBoards[tag-1].makeControlsHidden(true)
UIView.animate(withDuration: 0.3) { self.superview?.layoutIfNeeded() }
}

关于ios - 滑动菜单 - 从右向左移动并向后移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40524798/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com