小编cph*_*117的帖子

按返回键时隐藏软键盘

我在SO上搜索了六个其他答案,但没有找到一个有效的答案.我只想在用户按下回车键时关闭软键盘.(相当于疯狂的iOS'resignKeyboard'调用.)在下面的代码中,不会调用onEditorAction方法.我在我的XML文件中设置了EditText视图,片段中的代码如下:

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        fragView = inflater.inflate(R.layout.fragment_encrypt2, container, false);
        textField = (EditText) fragView.findViewById(R.id.textField);

        textField.setOnEditorActionListener(new TextView.OnEditorActionListener() {

            @Override
            public boolean onEditorAction(TextView arg0, int actionId,
                                          KeyEvent arg2) {
                // hide the keyboard and search the web when the enter key
                // button is pressed
                if (actionId == EditorInfo.IME_ACTION_GO
                        || actionId == EditorInfo.IME_ACTION_DONE
                        || actionId == EditorInfo.IME_ACTION_NEXT
                        || actionId == EditorInfo.IME_ACTION_SEND
                        || actionId == EditorInfo.IME_ACTION_SEARCH
                        || (arg2.getAction() == KeyEvent.KEYCODE_ENTER)) {
                    InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(textField.getWindowToken(), …
Run Code Online (Sandbox Code Playgroud)

android actionlistener android-softkeyboard android-input-method

31
推荐指数
4
解决办法
3万
查看次数

会话重启后AVcapture会话缓慢启动

我有一个主视图控制器,它可以分割成具有avcapturesession的第二个视图控制器.我第一次从主视图控制器切换到捕获会话控制器,大约需要50ms(使用"仪器"检查).然后我从捕获会话中回到主视图控制器,然后从主控制器返回到avcapturesession控制器.每次从主视图控制器切换到avcapturesession需要更长的时间,并且通过第5次或第6次迭代,segue需要大约10秒.(与第一次50ms相比.)我已经粘贴了下面的avcapture会话的相关代码.谁能帮忙解决这个问题?谢谢

此类(类型为NSObject)管理
实际实现avcapturesession 的第二个视图控制器的捕获会话

#import "CaptureSessionManager.h"

@implementation CaptureSessionManager

@synthesize captureSession;
@synthesize previewLayer;

#pragma mark Capture Session Configuration

- (id)init {
    if ((self = [super init])) {
        [self setCaptureSession:[[AVCaptureSession alloc] init]];
    }
    return self;
}

- (void)addVideoPreviewLayer {
    [self setPreviewLayer:[[[AVCaptureVideoPreviewLayer alloc] initWithSession:[self     captureSession]] autorelease]];
    [[self previewLayer] setVideoGravity:AVLayerVideoGravityResizeAspectFill];

}

- (void)addVideoInput {
        AVCaptureDevice *videoDevice = [AVCaptureDevice   defaultDeviceWithMediaType:AVMediaTypeVideo];
     if (videoDevice) {
         NSError *error;
        AVCaptureDeviceInput *videoIn = [AVCaptureDeviceInput  deviceInputWithDevice:videoDevice error:&error];
        if (!error) {
           if ([[self captureSession] canAddInput:videoIn])
               [[self captureSession] addInput:videoIn];

        //else
        //  NSLog(@"Couldn't add …
Run Code Online (Sandbox Code Playgroud)

performance ios avcapturesession

14
推荐指数
2
解决办法
7165
查看次数

PEM到Android中的PublicKey

我见过很多类似的问题,但没有什么对我有用.我只是尝试将我从服务器检索到的PEM格式的RSA公钥转换为PublicKeyAndroid中的公钥.谁能指出我正确的方向?

编辑:我已成功使用以下代码将PEM转换为PublicKey,但在编码消息时,我得到意外的输出...

 public PublicKey getFromString(String keystr) throws Exception
    {
        // Remove the first and last lines

        String pubKeyPEM = keystr.replace("-----BEGIN PUBLIC KEY-----\n", "");
        pubKeyPEM = pubKeyPEM.replace("-----END PUBLIC KEY-----", "");

        // Base64 decode the data

        byte [] encoded = Base64.decode(pubKeyPEM);
        X509EncodedKeySpec keySpec = new X509EncodedKeySpec(encoded);
        KeyFactory kf = KeyFactory.getInstance("RSA");
        PublicKey pubkey = kf.generatePublic(keySpec);

        return pubkey;
    }

    public String RSAEncrypt(final String plain) throws NoSuchAlgorithmException, NoSuchPaddingException,
            InvalidKeyException, IllegalBlockSizeException, BadPaddingException, IOException {

        if (pubKey!=null) {
            cipher = Cipher.getInstance("RSA");
            cipher.init(Cipher.ENCRYPT_MODE, pubKey);
            encryptedBytes = …
Run Code Online (Sandbox Code Playgroud)

java android rsa pem

6
推荐指数
1
解决办法
4572
查看次数

覆盖UIImageView的图像getter/setter方法

我正在为UIImageView创建子类,因此每次设置图像属性时都会发生动画.以下是成功的:

import UIKit

class AnimatedImageView: UIImageView {

var img: UIImage! {
    get {
        return self.image
    }
    set {
        self.image = newValue

        UIView.animateWithDuration(0.5, delay: 0.4, usingSpringWithDamping: 0.2, initialSpringVelocity: 5.0, options: .CurveEaseIn, animations: {_ in

            self.transform = CGAffineTransformMakeScale(1.1, 1.1);

            }, completion: {_ in
                self.transform = CGAffineTransformIdentity;
        })
    }
}
Run Code Online (Sandbox Code Playgroud)

这并不奇怪.我将UIImageView子类化并添加了一个名为'img'的全新变量,该变量又修改了UIImageView的'image'属性.

问题是最终用户可能会改变AnimatedImageView的'image'属性.

import UIKit

class AnimatedImageView: UIImageView {

override var image: UIImage! {
 get {
     return self.image
 }
 set {
    self.image = newValue

    UIView.animateWithDuration(0.5, delay: 0.4, usingSpringWithDamping: 0.2, initialSpringVelocity: 5.0, options: .CurveEaseIn, animations: …
Run Code Online (Sandbox Code Playgroud)

overriding uiimageview ios swift

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

Swagger 不验证枚举查询参数

我正在使用 swagger 2.0 来定义我的 API。我正在使用这里的文档中描述的枚举。我的 swagger.yml 文件中有以下端点:

/my-endpoint:
    x-swagger-router-controller: my-controller
    get:
      summary: my test endpoint
      parameters:
        - name: feeling
          in: query
          type: string
          enum:
            - happy
            - sad
          required: true
      produces:
        - application/json
      responses:
        200:
          description: OK
Run Code Online (Sandbox Code Playgroud)

400 bad request如果feeling查询参数不是happyor sad,我希望 a返回给客户端,但它接受任何字符串。swagger 不验证参数是否在枚举中?

node.js swagger swagger-2.0

5
推荐指数
0
解决办法
833
查看次数

Django UserManager create_user 失败,“NoneType”对象不可调用

我几乎逐字地遵循了这个自定义 Django 用户模型示例中的代码,当我尝试创建一个用户时,它在最后一个参数上失败self.model并出现错误

TypeError: 'NoneType' object is not callable
Run Code Online (Sandbox Code Playgroud)

相关代码片段如下:

class MyUserManager(BaseUserManager):

def create_user(self, email, password=None, 
                first_name=None, 
                last_name=None
               ):
    now = timezone.now()
    if not email:
        raise ValueError('The given email must be set')
    email = self.normalize_email(email)

    user = self.model(email=email, 
                        first_name=first_name, 
                        last_name=last_name
                      )

    user.set_password(password)
    user.save(using=self._db)
    return user

class MyUser(AbstractBaseUser, PermissionsMixin):

email = models.EmailField(_('email address'), max_length=254, unique=True)
first_name = models.CharField(_('first name'), max_length=30, blank=False)
last_name = models.CharField(_('last name'), max_length=30, blank=False)

objects = MyUserManager()

USERNAME_FIELD = 'email'
REQUIRED_FIELDS = []

class …
Run Code Online (Sandbox Code Playgroud)

python authentication django model

3
推荐指数
1
解决办法
1562
查看次数

Django 和 React 被禁止 403

我使用 create-react-app 结合 Django Rest Framework 制作了一个小型网站。npm start当我使用 Django API 从一个端口到另一个端口时,一切都运行良好。然而,当我npm build静态反应文件并从 Django 应用程序内提供它们时,我403 forbidden在遇到多个端点时遇到了问题。我认为这与 CSRF 有关,但我不知道是什么。

我从以下位置提供静态文件views.py

@api_view(['GET'])
def serve_html(request):
    try:
        with open(os.path.join(REACT_APP_DIR, 'build', 'index.html')) as f:
            return HttpResponse(f.read())
    except FileNotFoundError:
        return HttpResponse(
            """
            This URL is only used when you have built the production
            version of the app. Visit http://localhost:3000/ instead, or
            run `yarn run build` to test the production version.
            """,
            status=501,
        )
Run Code Online (Sandbox Code Playgroud)

我的urls.py底部包含静态文件的总览:

urlpatterns = [ …
Run Code Online (Sandbox Code Playgroud)

python django django-rest-framework create-react-app

2
推荐指数
1
解决办法
3910
查看次数