我正在设置背景图像来查看控制器.但我也想在这个背景下添加模糊效果.我怎样才能做到这一点?
我用以下代码设置背景:
self.view.backgroundColor = UIColor(patternImage: UIImage(named: "testBg")!)
Run Code Online (Sandbox Code Playgroud)
我发现在互联网上模糊imageview我怎么能实现这个到我的背景?
var darkBlur = UIBlurEffect(style: UIBlurEffectStyle.Dark)
// 2
var blurView = UIVisualEffectView(effect: darkBlur)
blurView.frame = imageView.bounds
// 3
imageView.addSubview(blurView)
Run Code Online (Sandbox Code Playgroud) 我想转换byte为JsonObject.我试过这样的:
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
String testV=new JsonObject(new String(responseBody));
}
Run Code Online (Sandbox Code Playgroud)
但我收到编译器错误:
JsonObject cannot be applied to java.lang.String
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
网页有一个按钮,木偶操作者必须尽快单击该按钮,按钮变为可见。此按钮并非始终可见,而是同时对所有人可见。所以我必须不断刷新才能发现按钮变得可见。我写了下面的脚本来做到这一点:
const browser = await puppeteer.launch({
headless: true,
args: ['--no-sandbox']
});
const page = await browser.newPage()
await page.setViewport({ width: 1920, height: 1080})
//I am calling my pageRefresher method here
async function pageRefresher(page,browser, url) {
try {
await page.goto(url, {waitUntil: 'networkidle2'})
try {
await page.waitForSelector('#ourButton', {timeout: 10});
await page.click('#ourButton')
console.log(`clicked!`)
await browser.close()
} catch (error) {
console.log('catch2 ' + counter + ' ' + error)
counter += 1
await pageRefresher(page, browser, url)
}
}catch (error) {
console.log('catch3' + error)
await browser.close(); …Run Code Online (Sandbox Code Playgroud) 我收到了用户的崩溃报告,但我不了解崩溃报告.
它说:
Ribony: function signature specialization <Arg[0] = Owned To Guaranteed and Exploded, Arg[1] = Owned To Guaranteed and Exploded, Arg[2] = Owned To Guaranteed and Exploded, Arg[3] = Exploded, Arg[4] = Owned To Guaranteed> of Ribony.ChatManager.sendMessage (Ribony.ChatManager)(Swift.String, to : Swift.String, anonClosed : Swift.String, toWeb : Swift.Int) -> () + 3608
Run Code Online (Sandbox Code Playgroud)
我正在使用swift.这是什么报告?我的sendMessage方法:
func sendMessage(message: String,to: String,anonClosed: String,toWeb: Int) {
NSNotificationCenter.defaultCenter().postNotificationName(mySpecialNotificationKey, object: self,userInfo:["message":message])
var sender=""
var token=""
var toSubstr=""
if count(to) >= 5 {
let rangeOfTo = Range(start: to.startIndex, …Run Code Online (Sandbox Code Playgroud) 我正在使用片段,我在片段中有一个编辑文本,我想在主要活动中获得价值。
\n\n这是我的片段布局
\n\n<?xml version="1.0" encoding="utf-8"?>\n<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"\n android:layout_width="match_parent"\n android:layout_height="match_parent"\n android:orientation="vertical"\n android:background="#878787" >\n\n <TextView android:layout_width="fill_parent"\n android:layout_height="wrap_content"\n android:gravity="center"\n android:text="dfgdfgdf"\n android:textSize="20dp"\n android:layout_centerInParent="true"\n android:id="@+id/user_name"/>\n\n <EditText\n android:id="@+id/message"\n android:layout_width="fill_parent"\n android:layout_height="wrap_content"\n />\n\n <Button \n android:text="G\xc3\xb6nder"\n android:layout_width="fill_parent"\n android:layout_height="wrap_content"\n android:onClick="getFromUser"\n android:layout_marginTop="40dp"\n />\n\n</RelativeLayout>\nRun Code Online (Sandbox Code Playgroud)\n\n我正在使用此函数加载片段:
\n\npublic void startChat(JsonObject user) {\n FrameLayout layout = (FrameLayout)findViewById(R.id.container);\n layout.setVisibility(View.VISIBLE); \n Bundle bundle = new Bundle();\n bundle.putString("name", user.get("name").getAsString());\n sendTo=user.get("username").getAsString();\n FragmentManager fragmentManager = getSupportFragmentManager();\n FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();\n ConversationFragment conv = new ConversationFragment();\n conv.setArguments(bundle);\n fragmentTransaction.add(R.id.container, conv);\n fragmentTransaction.commit();\n viewPager.setVisibility(View.GONE);\n actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);\n actionBar.setDisplayHomeAsUpEnabled(true);\n\n}\nRun Code Online (Sandbox Code Playgroud)\n\n这是我的片段类
\n\npublic …Run Code Online (Sandbox Code Playgroud) 我想在imageview中添加一个进度条.我尝试使用以下代码:
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/image"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="3dp"
android:src="@drawable/defaultprofile" />
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="64dp"
android:layout_height="64dp"
android:indeterminate="false"
android:progressDrawable="@drawable/circular_progress_bar"
android:background="@drawable/circle_shape"
style="?android:attr/progressBarStyleHorizontal"
android:max="100"
android:progress="65"
android:layout_alignParentTop="true"
android:layout_alignLeft="@+id/image"
android:layout_alignStart="@+id/image" />
Run Code Online (Sandbox Code Playgroud)
circular_progress_bar.xml:
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="270"
android:toDegrees="270">
<shape
android:innerRadiusRatio="2.5"
android:shape="ring"
android:thickness="1dp"
android:useLevel="true"><!-- this line fixes the issue for lollipop api 21 -->
<gradient
android:angle="0"
android:endColor="#007DD6"
android:startColor="#007DD6"
android:type="sweep"
android:useLevel="false" />
</shape>
</rotate>
Run Code Online (Sandbox Code Playgroud)
circle_shape.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:innerRadiusRatio="2.5"
android:thickness="1dp"
android:useLevel="false">
<solid android:color="#CCC" />
</shape>
Run Code Online (Sandbox Code Playgroud)
结果:
我该如何解决?进度条应该看起来像imageview的边框.我必须删除填充.
我正在尝试使用 MVVM 架构构建一个聊天应用程序,但我不知道在哪里放置我的套接字连接类,我需要一个想法或起点等。
单一数据源原则
我正在使用单一数据源的真实原则。举个例子:如果消息从套接字服务器发送到应用程序,我的套接字类应该将其保存到数据库,然后应该使用实时数据将其从数据库提供给观察者(因此它们将是视图模型)。
我的应用程序架构
我的应用程序包含不同的活动(聊天屏幕、对话屏幕等),这些活动将观察我的套接字连接存储库类。此外,如果用户关闭应用程序,我的套接字连接将随应用程序一起终止。我不需要任何后台连接。
我在问什么?
实现此功能的最佳方法是什么:
1) Socket 类应该使用实时数据,因为 activites 会观察到它。所以它应该是一个存储库。2)我的套接字类应该在应用程序打开时始终存在。
我应该为套接字存储库使用什么?服务或单例类或不同的东西?你有什么建议?我应该在哪里启动套接字连接存储库?来自应用程序类还是不同的东西?
我正在尝试使用 Alamofire 5 发出发布请求。我必须使用Dictionary<String, Any>参数。因为我正在为 Alamofire 编写一个包装器。但似乎我无法使用字典中的任何对象,因为 Alamofire 给了我一个编译器错误:
Value of protocol type 'Any' cannot conform to 'Encodable'; only struct/enum/class types can conform to protocols
Run Code Online (Sandbox Code Playgroud)
我尝试过的:
let encodedParameters = Dictionary<String, Any>
AF.request(url, method: .get, parameters: encodedParameters, headers: headers)
Run Code Online (Sandbox Code Playgroud)
在我的字典中,某些值将是字符串,其他值将是整数。所以我不能使用常量类型。我该如何解决这个问题?
我正在尝试在我的应用程序中实现“实时活动”。我正在关注苹果文档。
链接:https ://developer.apple.com/documentation/activitykit/displaying-live-data-with-live-activities
示例代码:
struct LockScreenLiveActivityView: View {
let context: ActivityViewContext<PizzaDeliveryAttributes>
var body: some View {
VStack {
Spacer()
Text("\(context.state.driverName) is on their way with your pizza!")
Spacer()
HStack {
Spacer()
Label {
Text("\(context.attributes.numberOfPizzas) Pizzas")
} icon: {
Image(systemName: "bag")
.foregroundColor(.indigo)
}
.font(.title2)
Spacer()
Label {
Text(timerInterval: context.state.deliveryTimer, countsDown: true)
.multilineTextAlignment(.center)
.frame(width: 50)
.monospacedDigit()
} icon: {
Image(systemName: "timer")
.foregroundColor(.indigo)
}
.font(.title2)
Spacer()
}
Spacer()
}
.activitySystemActionForegroundColor(.indigo)
.activityBackgroundTint(.cyan)
}
}
Run Code Online (Sandbox Code Playgroud)
实际上,代码非常简单。我们可以使用timerInterval来制作倒计时动画。但是当计时器结束时,我想更新实时活动视图。如果用户重新打开应用程序,我可以更新它,但是如果用户不打开应用程序会发生什么?有没有办法在不使用推送通知的情况下更新实时活动?