One of my friends once said that scaling and rotating an image on a multi-touch screen should be as basic as "Hello World" in the program. I think this is very reasonable. In the first part of the video (two parts in total), I will explain how to make the flex component rotate and zoom. The following class allows the image to be scaled and rotated, which is as classic as "Hello World" and also applies to videos and containers. This greatly enhances the user experience.
The following is the content of the class, which can be applied in most programs.
Rotatablescalable:
- Package com. mlegrand
- {
- Import flash. display. displayobject;
- Import flash. Events. transformgestureevent;
- Import flash. Geom. matrix;
- Import flash. Geom. Point;
- Import flash. UI. multitouch;
- Import flash. UI. multitouchinputmode;
- Public class rotatablescalable
- {
- Protected var diso: displayobject
- Public Function rotatablescalable (displayobject: displayobject)
- {
- Diso = displayobject;
- If (multitouch. supportsgestureevents)
- {
- Multitouch. inputmode = multitouchinputmode. gesture;
- Addgestureeventlisteners ()
- }
- }
- Protected function addgestureeventlisteners (): void
- {
- Diso. addeventlistener (transformgestureevent. gesture_rotate, gesturerotatehandler );
- Diso. addeventlistener (transformgestureevent. gesture_zoom, gesturezoomhandler );
- }
- Protected function gesturerotatehandler (Event: transformgestureevent): void
- {
- Event. stopimmediatepropagation ();
- VaR M: matrix = diso. Transform. matrix;
- VaR P: Point = M. transformpoint (new point (diso. width/2, diso. Height/2 ));
- M. Translate (-p. x,-P. y );
- M. Rotate (event. Rotation * (math. PI/180 ));
- M. Translate (P. X, p. y );
- Diso. Transform. Matrix = m;
- }
- Protected function gesturezoomhandler (Event: transformgestureevent): void
- {
- Event. stopimmediatepropagation ();
- VaR M: matrix = diso. Transform. matrix;
- VaR P: Point = M. transformpoint (new point (diso. width/2, diso. Height/2 ));
- M. Translate (-p. x,-P. y );
- M. Scale (event. scalex, event. scaley );
- M. Translate (P. X, p. y );
- Diso. Transform. Matrix = m;
- }
- }
- }
Copy code Note: I have read some matrix changes on Justin Imhoff's blog. I strongly recommend that you subscribe to his blog through feed. I also noted that natural User Interface Group. This forum is very good. We recommend that you check out the friends and sisters who are interested in multi-touch. |
Reprinted: http://bbs.9ria.com/thread-44732-1-1.html