小编jos*_*das的帖子

在Swift中使用选择器的正确方法

我正在以编程方式创建视图,并添加一个函数,以便操作响应UIControlEvents.TouchUpInside事件:

button.addTarget(self, action: action, forControlEvents: 
UIControlEvents.TouchUpInside)
Run Code Online (Sandbox Code Playgroud)

因此,通过进入文档,我已将此操作添加为选择器:

#selector(ViewController.onRegularClick)
Run Code Online (Sandbox Code Playgroud)

然后XCode抱怨:

#selector的参数是指未向Objective-C公开的方法

所以我必须设置处理函数:

@objc func onRegularClick(sender: UIButton)
Run Code Online (Sandbox Code Playgroud)

有人可以通过引导我阅读文档,或者甚至给出简短的解释,将这个菜鸟放在正确的方向:

  1. 为什么我不能再简单地将函数名称String传递给动作?
  2. 如何按照Swift方式实现这个?使用Selector类?
  3. 为什么我们需要传递@objc关键字以及它如何影响函数?

谢谢!

selector ios swift

12
推荐指数
2
解决办法
7982
查看次数

使用软键盘向上移动一个布局,但在底部保留一个布局

我有以下TabHost布局:

<?xml version="1.0" encoding="iso-8859-1"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_margin="0dp"
    android:padding="0dp" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_margin="0dp"
        android:background="@drawable/main_app_background"
        android:orientation="vertical"
        android:padding="0dp" >

        <ImageView
            android:id="@+id/logo"
            android:layout_width="fill_parent"
            android:layout_height="@dimen/site_logo_height"
            android:layout_margin="0dp"
            android:background="@color/tab_subtitle_background"
            android:padding="0dp"
            android:src="@drawable/barlogo" />

        <FrameLayout
            android:id="@+id/tab_subtitle"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="0dp"
            android:gravity="center"
            android:padding="0dp" />

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="center"
            android:layout_margin="0dp"
            android:layout_weight="99"
            android:padding="0dp" />

        <Button
            android:id="@+id/btn_save"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="15dp"
            android:layout_marginTop="7dp"
            android:focusableInTouchMode="true"
            android:imeOptions="actionNext"
            android:tag="done"
            android:text="Ok" />

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="0dp"
            android:layout_weight="1"
            android:padding="0dp" />
    </LinearLayout>

</TabHost>
Run Code Online (Sandbox Code Playgroud)

问题是,当软键盘出现时,Button和TabWidget都向上移动.

我的目标是将TabWidget保持在底部(软键盘下方),然后让Ok按钮向上移动(在键盘顶部).可能吗?

提前致谢!

android view android-widget android-layout android-softkeyboard

5
推荐指数
1
解决办法
1259
查看次数