我已经实现了switch语句。现在,我正在努力添加一个双击手势,以显示更多有关从开关中选择的盒子的信息。
#here's the data
df <- structure(list(`Year` = c(2012, 2012, 2012, 2013, 2013, 2013, 2014, 2014, 2014),
`continent` = c("Africa", "Asia", "Europe", "Africa", "Asia", "Europe", "Africa", "Asia", "Europe"),
`Cash` = c(400000, 410000, 200000, 300000, 500000, 250000, 400000, 600000, 500000)),
row.names = c(NA, -9L), class = c("tbl_df", "tbl", "data.frame"))
#here's my attempt at plotting it
ggplot(df, aes(Year, Cash, group = continent)) +
geom_line(aes(colour = continent)) +
geom_segment(aes(xend = 2012, yend = Cash), linetype = 2, colour = 'grey')+
geom_point(size = 2, colour = "white") +
geom_text(aes(x = 2012.1, label = continent), hjust = 0)+
transition_reveal(continent, Year) +
coord_cartesian(clip = 'off') +
theme(plot.margin = margin(5.5, 40, 5.5, 5.5), legend.position = "none")
#I am getting the error below
Error in ggproto(NULL, TransitionReveal, params = list(along_quo = along_quo, :
object 'Year' not found
#when I remove continent from transition_reveal, i get a plot but it doesn't look nice at all.
#I would like to plot something similar to the picture below
答案 0 :(得分:1)
我只写一些示例代码。希望对您有所帮助。
就像下面的代码一样,您可以使用双击动作。
class ViewController: UIViewController {
var singleTap: UITapGestureRecognizer!
var doubleTap: UITapGestureRecognizer!
override func viewDidLoad() {
super.viewDidLoad()
doubleTap = UITapGestureRecognizer(target: self, action: #selector(tap(gesture:)))
view.addGestureRecognizer(doubleTap)
doubleTap.numberOfTapsRequired = 2
doubleTap.delaysTouchesBegan = true
singleTap = UITapGestureRecognizer(target: self, action: #selector(tap(gesture:)))
singleTap.delaysTouchesBegan = true
singleTap.require(toFail: doubleTap)
view.addGestureRecognizer(singleTap)
}
@objc
func tap(gesture: UITapGestureRecognizer) {
switch gesture {
case singleTap:
moreInfo(option: 1)
case doubleTap:
moreInfo(option: 2)
default:
print("---")
}
}
func moreInfo(option: Int) {
switch option {
case 1:
print("more information for 1")
case 2:
print("more information for 2")
default:
print("---")
}
}
}