我是 SwiftUI 的新手。我想每个人都在这一点上。我已经做了大约 6 年的应用程序开发人员,我觉得在 StackOverflow 上问这个问题很愚蠢。但我到处看。如何在 SwiftUI 的 ImageView 中居中裁剪图像?
我知道有一个选项可以更改纵横比,但我只看到适合和填充。我只是想让 imageView 居中裁剪(android 术语)图像。有人知道吗?
所以我试图使用rpush来使用这个gem的移动应用程序的推送通知:https://github.com/rpush/rpush.我正在使用sinatra框架.但我一直得到这个错误,即使我在我的文件顶部写了 - > require'rpush'.有人在红宝石中有经验可以帮助我吗?我是红宝石的新手所以请耐心等待.这是我的代码
require 'rpush'
Module Notifier
def rpush_client
app = Rpush::Gcm::App.new
app.name = "App-Name"
app.auth_key = "XXXXXXXXXXXXXXX"
app.connections = 1
app.save!
end
def notify(user_id,alert)
rpush_client
session = db_find_one('dbname.sessions',{user_id: user_id})
if session.present?
device = session['devices'].first
token = device['device_token']
n = Rpush::Gcm::Notification.new
n.app = Rpush::Gcm::App.find_by_name("App-Name")
n.registration_ids = ["token", token]
n.data = { message: alert }
n.save!
Rpush.push
end
end
end
Run Code Online (Sandbox Code Playgroud)
我知道这是一个愚蠢的问题,但厌倦了在这里寻找它.
我一直致力于生成二维码并将其显示在屏幕上。现在我可以使用 Zxing 库生成它,该库为我提供了一个 BitMatrix,该 BitMatrix 返回 x 和 y 值的布尔值(如果该坐标需要为黑色或白色)。现在我可以使用以下代码成功生成并显示二维码:
String charset = "UTF-8";
Map<EncodeHintType, ErrorCorrectionLevel> hintMap = new HashMap<>();
hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
BitMatrix matrix = new QRCodeWriter().encode(new String(url.getBytes(charset), charset), BarcodeFormat.QR_CODE, (int) context.getResources().getDimension(R.dimen.qr_square), (int) context.getResources().getDimension(R.dimen.qr_square), hintMap);
Bitmap bitmap = Bitmap.createBitmap(matrix.getWidth(), matrix.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setColor(Color.BLACK);
for (int y = 0; y < matrix.getHeight(); y++) {
for (int x = 0; x < matrix.getWidth(); x++) {
if (!overlayRect.contains(x, y))
canvas.drawPoint(x, y, paint);
}
} …Run Code Online (Sandbox Code Playgroud)