ios - Stripe 布局 ios 键盘默认隐藏。

标签 ios stripe-payments

我正在使用为卡片详细信息创建 View 的 strip SDK。代码如下:

//live key
NSString *cardApiKey;

if([hostType isEqualToString:@"production"])
{
    cardApiKey = @"xxxxxxxxxxxxxxxxxxxxx";
} else {
    cardApiKey = @"xxxxxxxxxxxxxxxxxxxxx";
}

self.stripeView = [[STPView alloc] initWithFrame:CGRectMake(10, _cardDetailsLabel.frame.origin.y+_cardDetailsLabel.frame.size.height+10, 200, 55) andKey:cardApiKey];

[self.canvasView addSubview:self.stripeView];

self.stripeView.delegate = self;

问题是数字键盘键盘默认显示。我不希望每次启动 strip View 时都会弹出数字键盘。我怎样才能解决这个问题?谢谢。

最佳答案

方法一:使用自定义 View

您可以使用自定义 View 而不是 STPView,它可以让您完全控制何时触发键盘。然后,您可以只填充 STPCart 的一个实例。 Stripe gighub 页面在以下部分描述了这种方法: '使用你自己的观点' .

https://github.com/stripe/stripe-ios

STPCard *card = [[STPCard alloc] init];
card.number = @"4242424242424242";
card.expMonth = 12;
card.expYear = 2020;

方法 2:使用 Stripes STPView 实现

要使用 Stripe 的 STPView 执行此操作,您可以使用在有问题的 UITextField 子类上为 UIControlEventEditingDidBegin 事件使用 addTarget 的方法。您可以在 View 加载后将其删除,因为不再需要它:
// YourViewController.h

#import <UIKit/UIKit.h>
#import "YourViewController.h"

@class STPView;

@interface YourViewController : UIViewController

@property (strong,nonatomic) STPView *stripeView;

@end

// YourViewController.m

#import "YourViewController.h"
#import "STPView.h"
#import "PKView.h"
#import "PKTextField.h"

@interface YourViewController ()
@end

@implementation YourViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Create your STPView instance
    _stripeView = [[STPView alloc] initWithFrame:CGRectMake(15,20,290,55) andKey:@"perishable_key"];
    [self.view addSubview:_stripeView];
    // Add target for editingDidBegin UIControl event
    [_stripeView.paymentView.cardNumberField addTarget:self action:@selector(editingBegan:) forControlEvents:UIControlEventEditingDidBegin];
}

- (void)editingBegan:(id)sender
{
    // Hide the keyboard
    [_stripeView.paymentView.cardNumberField resignFirstResponder];
    // Remove the addTarget
    [_stripeView.paymentView.cardNumberField removeTarget:self action:@selector(editingChanged:) forControlEvents:UIControlEventEditingDidBegin];
}

@end

卡号字段 是 PKTextField(UITextField 的子类)的一个实例,也是在创建 STPView 时获得焦点的 View 。

关于ios - Stripe 布局 ios 键盘默认隐藏。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22405651/

相关文章:

ios - 如何在邮件应用程序 iOS9 Swift/obj-C 中为单元格创建可扩展(可拉伸(stretch))操作

paypal - 地址验证系统 (AVS) ) 检查电子商务

javascript - Laravel 中的 Stripe.js 错误

javascript - 创建自定义表单以使用 Stripe 接受信用卡

c# - iOS - 从 Xcode 发布 iOS 应用程序时出错

ios - 如何访问核心图中单个条的CALayer?

ios - 无法使用IntelliJ IDEA将ipa上传到appstore

javascript - Stripe Checkout.js token 回调是否会阻塞,直到付款处理完毕?

php - 如何用stripe api向别人的银行账户汇款

ios - 以单一名称将多个对象保存到核心数据