tailieunhanh - iPhone Cool Projects phần 6

Hình 4-10. Hai cản được tạo ra bằng cách kéo các hình ảnh từ thư viện giao diện Builder Media vào cửa sổ tài liệu. Hình 4-11. Các lớp học 'cản sau đó đã được thay đổi từ UIImageView GadgetView sử dụng Thanh tra nhận dạng. | CHAPTER 4 All Fingers and Thumbs Multitouch Interface Design and Implementation 95 Figure 4-10. The two bumpers were created by simply dragging the images from the Interface Builder Media library into the document window. Figure 4-11. The bumpers class was then changed from UllmageView to Gadgetview using the Identity Inspector. We don t process any gestures for three or more fingers so we filter them out early. There s no reason you couldn t add your own processing here at least no technical reason. Whether it s advisable or not from a user-experience perspective is another question. So this is how we handle a two-finger gesture else if allTouches count 2 NSArray twoTouches allTouches allObjects NSSet is unordered we get the touches into an array which doesn t sort it for us but at least we can address each touch individually even if we don t know which is which yet. lastPinch self calculatePinch twoTouches lastRotation self calculateAngle twoTouches lastCenter self averageTouchPoint twoTouches We ll look at the implementations of these methods later the important thing is that we re initializing three tracking variables a floating-point number to track the distance between the fingers another to track their relative angle and a CGPoint to track the midpoint between them. 96 CHAPTER 4 All Fingers and Thumbs Multitouch Interface Design and Implementation We ll also need to track whether we ve locked the interface into a particular gesture. When performing two-finger drags we ll set the modeLock to either lockToXAxis or lockToYAxis and when interacting with the mode-locked gadget we may set it to lockToRotation or lockToScale. Until then it defaults to lockNotYetChosen if modeLock lockNotYetChosen axisLockedDrag YES originalCenter lastCenter Until we get some sign that the user s performing a more specialized gesture we can only assume that two fingers on the screen could mean a two-finger drag. We ll initialize for this but note the test we do first as it s a .