小编Sri*_*isa的帖子

ios模拟器:模拟滑动和拖动

我在UIScrollView中有一个UIView.当我想在UIView上模拟拖动事件时,正在触发UIScrollView上的滑动事件.

根据文档,滑动和拖动之间没有太大区别.
刷卡

1- Place the pointer at the start position.  
2- Hold the mouse button. 
3- Move the pointer in the swipe direction and release the mouse button.
Run Code Online (Sandbox Code Playgroud)


拖动

1- Place the pointer at the start position.
2- Hold down the mouse button.
3- Move the pointer in the drag direction.
Run Code Online (Sandbox Code Playgroud)

在ipad上我可以用两根手指两次轻扫和一根手指拖动.现在,我如何在模拟器上做类似的事情; 拖动而不是滑动?

编辑1:我应该先清楚一点.无论如何,我的问题是鼠标拖动是触发滑动而不是拖动,从而滚动滚动视图而不是将拖动事件传递给滚动视图包含的UIView.我在macbook pro上.触摸板上的双指滑动被忽略.触摸和拖动导致与鼠标拖动相同的操作.谢谢

objective-c drag swipe ios ios-simulator

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

Rails:上传文件的校验和

我在Ruby on Rails中生成上传图像的校验和(sha256).

upload = params[:file]
data1 = upload.read
data2 = File.read(upload.tempfile)
checksum1 = Digest::SHA256.hexdigest(data1)
checksum2 = Digest::SHA256.hexdigest(data2)
puts checksum1
puts checksum2
Run Code Online (Sandbox Code Playgroud)

最后两个语句返回不同的值.checksum1是通过使用UploadedFile对象读取数据生成的.checksum2是通过从文件系统读取临时文件生成的.

ActionDispatch :: Http :: UploadedFile的对象是否返回比上传文件的内容更多的内容?当我生成写入文件系统的上传文件的校验和时,它与checksum2(临时文件校验和)匹配,而不是与checksum1(UploadedFile.read)匹配.

我假设通过从文件系统读取临时文件生成的校验和更可靠,因为对象(UploadedFile)实现可能会更改.如果需要,可以更轻松地生成文件系统上现有文件的校验和.

那么,校验和差异的原因是什么,哪一个更可靠?

谢谢.


更新1:根据@ pablo-castellazzi的建议,我使用Digest :: SHA256.file(upload.path).hexdigest生成哈希.我们称之为校验和3

checksum3等于checksum1但与checksum2不同


更新2:如果我使用二进制模式读取@ Arsen7提到的文件,那么所有校验和都是相同的.

windows checksum file-upload ruby-on-rails sha256

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

fmt.Println调用Error而不是String()

我有这个代码

package main

import (
    "fmt"
    "math"
)

type ErrNegativeSqrt float64

func (s ErrNegativeSqrt) String() string {
    return fmt.Sprintf("%f", float64(s))
}

func (e ErrNegativeSqrt) Error() string {
    return fmt.Sprintf("Cannot Sqrt negative number: %v", float64(e))
}

func Sqrt(x float64) (ErrNegativeSqrt, error) {
    if x < 0 {
        e := ErrNegativeSqrt(x)
        return e, e
    } else {
        return ErrNegativeSqrt(math.Sqrt(x)), nil
    }
}

func main() {
    fmt.Println(Sqrt(2))
    fmt.Println(Sqrt(-2))
}
Run Code Online (Sandbox Code Playgroud)

这段代码的输出是

不能Sqrt负数:1.4142135623730951 <nil>不能Sqrt负数:-2不能Sqrt负数:-2

当我为ErrNegativeSqrt实现Stringer接口时,为什么fmt.Println调用Error()方法而不是String()方法?

我是新手,所以我可能会遗漏一些非常明显的东西.

go

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