小编cod*_*man的帖子

使用 UIImageView 动画创建流畅的动画

我目前正在 4 张图像之间制作动画,如下所示:

UIImageView *tom3BeforeImage;
tom3Images = [NSArray arrayWithObjects: [UIImage imageNamed:@"floortom_before1.png"],[UIImage imageNamed:@"floortom_before2.png"],[UIImage imageNamed:@"floortom_before3.png"],[UIImage imageNamed:@"floortom_before4.png"], nil ];
tom3BeforeImage.animationImages = tom3Images;
tom3BeforeImage.animationDuration = 0.75;
[tom3BeforeImage startAnimating];
Run Code Online (Sandbox Code Playgroud)

它工作正常,除了图像之间的动画断断续续。我需要的持续时间正好是 0.75 秒,所以加快速度不是一种选择。

让动画在图像之间更平滑的最佳方法是什么,有点像在每个图像变化之间进行混合?

谢谢!

objective-c ios

4
推荐指数
2
解决办法
2077
查看次数

在所有UIWebView请求上添加自定义http头字段

我正在使用以下代码为我的UIWebView发送的请求设置自定义HTTP标头.问题是我看到页面加载一秒钟然后它进入白色/空白屏幕.我已经测试了不同的URL,但行为是相同的.有任何想法吗?

func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
        var headerIsPresent = false
        let headerFields = request.allHTTPHeaderFields
        for headerField in headerFields?.keys.array as [String] {
            if headerField == "X-Test-App" {
                headerIsPresent = true
            }
        }

        if headerIsPresent {
            return true
        } else {
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {
                dispatch_async(dispatch_get_main_queue(), {
                let url = request.URL
                var newRequest: NSMutableURLRequest = request as NSMutableURLRequest

                // set new header
                newRequest.addValue("MyValue", forHTTPHeaderField: "X-Test-App")

                // reload the request
                self.webView.loadRequest(newRequest)
                })
            })
            return false
        }
    }
Run Code Online (Sandbox Code Playgroud)

uiwebview ios swift

4
推荐指数
1
解决办法
8736
查看次数

在紧凑视图中显示按钮的MediaStyle通知

我正在使用MediaStyle进行推送通知,以便我可以显示当前播放的歌曲元数据以及包含暂停按钮.我看到的问题是我的通知不会自动展开以显示暂停按钮,即使我已经包含了setShowActionsInCompactView().如果我在锁定屏幕上下拉通知,它会展开,然后显示暂停按钮.但我希望它能显示按钮而不会扩展.

显示通知的屏幕截图:http: //cl.ly/image/3E2D0m403v1b

下拉展开后如何显示通知的屏幕截图:http: //cl.ly/image/1N1i0G121i2Y

以下是我用于生成通知的代码段:

        PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(getApplicationContext(), MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
        Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
        Intent intent = new Intent(BROADCAST_PLAYER_STOP);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);

        NotificationCompat.Builder notification = new NotificationCompat.Builder(this)
                .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                .setContentTitle(getResources().getString(R.string.app_name))
                .setTicker(tickerString)
                .setContentText(contentString)
                .setSmallIcon(R.drawable.ic_notification)
                .setLargeIcon(icon)
                .addAction(R.drawable.ic_media_pause, "", pendingIntent)
                .setContentIntent(pi)
                .setStyle(new android.support.v7.app.NotificationCompat.MediaStyle()
                        .setShowActionsInCompactView(0)
                        .setMediaSession(mSession.getSessionToken()))
                .setPriority(NotificationCompat.PRIORITY_MAX)
                .setWhen(0)
                .setOngoing(true);
        startForeground(NOTIFICATION_ID, notification.build());
Run Code Online (Sandbox Code Playgroud)

android android-notifications

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

ARKit - 从相机到锚点的距离

我正在创建一个锚点并将其添加到我的 ARSKView 在相机前面的一定距离处,如下所示:

func displayToken(distance: Float) {
        print("token dropped at: \(distance)")
        guard let sceneView = self.view as? ARSKView else {
            return
        }

        // Create anchor using the camera's current position
        if let currentFrame = sceneView.session.currentFrame {
            // Create a transform with a translation of x meters in front of the camera
            var translation = matrix_identity_float4x4
            translation.columns.3.z = -distance
            let transform = simd_mul(currentFrame.camera.transform, translation)

            // Add a new anchor to the session
            let anchor = ARAnchor(transform: transform)
            sceneView.session.add(anchor: anchor)
        }
    } …
Run Code Online (Sandbox Code Playgroud)

ios swift arkit

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

如何使用 HealthKit 睡眠查询区分来源

我目前正在使用以下代码来查询用户在过去 24 小时内睡眠的小时数:

   func getHealthKitSleep() {
        let healthStore = HKHealthStore()
        let sortDescriptor = NSSortDescriptor(key: HKSampleSortIdentifierEndDate, ascending: false)

        // Get all samples from the last 24 hours
        let endDate = Date()
        let startDate = endDate.addingTimeInterval(-1.0 * 60.0 * 60.0 * 24.0)
        let predicate = HKQuery.predicateForSamples(withStart: startDate, end: endDate, options: [])

        // Sleep query
        let sleepQuery = HKSampleQuery(
            sampleType: HKObjectType.categoryType(forIdentifier: HKCategoryTypeIdentifier.sleepAnalysis)!,
            predicate: predicate,
            limit: 0,
            sortDescriptors: [sortDescriptor]){ (query, results, error) -> Void in
                if error != nil {return}
                // Sum the sleep …
Run Code Online (Sandbox Code Playgroud)

ios swift healthkit

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