[英]Slide menu - move from right to left and back
I have slide menu when I click on screen menu comes out from right to left. 当我单击屏幕菜单时,我从右到左显示幻灯片菜单。 How can I write code if I click button to move back from left to right? 如果单击按钮从左向右移动,如何编写代码?
My slide menu: 我的幻灯片菜单:
My code: 我的代码:
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) =>
{
};
}
}
I use AutoLayout and UIView animation to move a view of controls up and down. 我使用AutoLayout和UIView动画上下移动控件视图。 (Think a keyboard but with more flexibility.) The board has a "Done" button, which animatedly moves the board (and it's subviews) out of view. (请考虑使用键盘,但具有更大的灵活性。)面板具有“完成”按钮,该按钮可以动态地将面板(及其子视图)移出视线。
Since I have an array of boards, there's extra code here addressing the tag property. 由于我有一块木板,因此这里有一些额外的代码可以解决tag属性。 That's where I find which board to work with. 那是我找到与哪个板一起工作的地方。
The key things are to: 关键是:
.. ..
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() }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.