iOS的滑块视图 [英] Slider view for iOS

查看:23
本文介绍了iOS的滑块视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮我解决这个问题吗?

Can someone help me with this scenario?

*有一个按钮,当点击它时,幻灯片会打开一个 UIView,点击的按钮仍然在它的左边.

*There is a button, which when tapped, slides opens up a UIView, with the tapped button still to its left.

*再次点击此按钮时,UIView 会向后滑动.

*This button when tapped again, makes the UIView slide back.

推荐答案

你描述的很简单.让我们称从右侧滑入的视图为抽屉(drawerView").将抽屉视图设置为视图控制器主视图的子视图.

What you describe is easy. Let's call the view that slides in from the right a drawer ("drawerView"). Set up the drawer view as a child view of your view controller's main view.

使抽屉"视图成为容器视图.把你想要的东西都放进去.(您的文本视图、按钮等)也将您的按钮放在此视图中.将该按钮连接到视图控制器中的操作slideDrawer".

Make that "drawer" view a container view. Put everything you want inside it. (Your text view, buttons, etc.) Also put your button inside this view. Connect that button to an action "slideDrawer" in your view controller.

然后确保剪辑子视图"为假,并使用向左箭头键将按钮从抽屉视图的左边缘移开.在IB中它会消失,但别担心.IB 不像您正在运行的程序那样尊重剪辑子视图"标志.

Then make sure "clips subviews" is false, and move the button off the left edge of the drawer view with the left arrow key. In IB it will disappear, but don't worry. IB doesn't honor the "clips subviews" flag like your running program will.

为您的 drawerView 创建一个插座并将其链接到您的代码.

Create an outlet to your drawerView and link it up to your code.

一旦您的抽屉视图完全符合您的要求,请注意它在尺寸检查器"中的 x 坐标.我们将该值称为 kVisibleX.然后将该视图向右拖动,直到它刚好离开屏幕.该按钮在 IB 中不可见,但在运行时仅在窗口边缘可见.(就像你在第一张图片中展示的那样)

Once you have your drawer view looking exactly how you want it, note it's x coordinate in the "size inspector". Let's call that value kVisibleX. Then drag that view to the right until it's just off-screen. The button won't be visible in IB, but will be visible just at the edge of the window at run-time. (like you show in your first image)

注意抽屉视图在屏幕外时的 x 坐标.我们将该值称为 kOffscreenX.

Note the x coordinate of the drawer view when it's offscreen. Let's call that value kOffscreenX.

向您的视图控制器添加一个布尔实例变量drawerIsShowing".

Add a boolean instance variable "drawerIsShowing" to your view controller.

现在编写一个IBAction方法slideDrawer:

Now write an IBAction method slideDrawer:

- (IBAction) slideDrawer: (id) sender;

在该方法中,检查 drawerIsShowing 以查看抽屉当前是否可见.如果是,请将其滑出屏幕.如果不是,请在屏幕上滑动.

In that method, check drawerIsShowing to see if the drawer is currently visible. If it is, slide it off-screen. If it's not, slide it on-screen.

- (IBAction) slideDrawer: (id) sender;
{
  CGFloat newX;
  if (drawerIsShowing)
    newX = kOffscreenX;
  else
    newX = kVisibleX;
  [UIView animateWithDuration: .25
  animations: 
  ^{
    CGRect drawerFrame = drawerView.frame;
    drawerFrame.origin.x = newX;
    drawerView.frame = drawerFrame;
  }
drawerIsShowing = !drawerIsShowing;
}

这篇关于iOS的滑块视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆