如何浏览一副扑克牌? [英] How to flick through a deck of cards?

查看:56
本文介绍了如何浏览一副扑克牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个iPhone纸牌游戏,其中每次使用都有一副纸牌,我想为用户提供在其纸牌上拖动手指的选项,并且每只纸牌都会在其手指上突出显示.此效果已在iPhone的Uno中完成.我的卡被放入UIButton中,我试图做的是在正常状态下将小图像设置为按钮,在突出显示状态下将较大图像设置为按钮,它确实达到了我想要的效果,但是用户必须突出显示每个按钮分别查看大图.

I'm making an iPhone cards game where each use has a deck of cards, I'd like to give the user the option to drag his finger through the cards and each card get's highlighted while his finger is on it. This effect is already done in Uno for iPhone. My cards are put into UIButton, what i tried to do is to set a small image to the button in normal state and a bigger image in the highlighted state, it did achieve the effect i was looking for but, the user has to highlight each card individually to be able to see the bigger picture.

这是我用来设置UIButton正常和突出显示状态的代码:

Here is the code i used to set the normal and highlighted state of the UIButton:

//player413 is an IBOutlet to a UIButton, and img,imgHigh are UIImages
[player413 setImage:img forState:UIControlStateNormal] ;
[player413 setImage:imgHigh forState:UIControlStateHighlighted] ;

任何准则?

推荐答案

使用单个视图来处理所有触摸交互.

Use a single view to handle all the touch interaction.

编辑:哦,好吧.

当视图接收到触摸时,将递归调用 hitTest:withEvent:,直到找到接受"触摸的视图为止.

When a view receives a touch hitTest:withEvent: is called recursively, until a view which "accepts" the touch is found.

一旦 hitTest:withEvent:返回一个非nil值,它就结束了(默认情况下);该视图拥有"触摸(请参见UITouch.view).只有该视图可以触摸Began/Moved/Ended/Cancelled:withEvent:回调.

Once hitTest:withEvent: returns a non-nil value, it's over (by default); that view "owns" the touch (see UITouch.view). Only that view gets touchesBegan/Moved/Ended/Cancelled:withEvent: callbacks.

如果您希望触摸影响牌组中的任何一张牌,则牌组应实现touches *:withEvent :,并在子视图上设置userInteractionEnabled = NO,或覆盖hitTest:withEvent:,以便它返回"self"而不是一个的卡片".

If you want the touch to affect any card in the deck, the deck should implement touches*:withEvent:, and either set userInteractionEnabled=NO on subviews, or override hitTest:withEvent: so it returns "self" instead of one of the "cards".

然后,在touches *:withEvent:中,检测触摸处于哪个卡"上,然后执行 card.highlighted = YES .如果您有multipleTouchEnabled = NO,则可以假定只有一键,并使用 UITouch * touch = [touches anyObject] .

Then, in touches*:withEvent:, detect which "card" the touch is on, and then do card.highlighted = YES. If you have multipleTouchEnabled=NO, you can assume that there's only one touch and use UITouch * touch = [touches anyObject].

(在触摸和它自己的视图之间有一些UIKit类:UIScrollView可以拦截触摸并滚动;手势识别器在检测到手势时取消触摸.)

(There are a handful of UIKit classes which somehow sit between the touch and its owning view: UIScrollView can intercept the touch and scroll instead; gesture recognizers cancel touches when they detect a gesure.)

这篇关于如何浏览一副扑克牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆