Use of various iOS gestures and UISlider
# Import "RootViewController. h"
@ Interface RootViewController ()
@ Property (nonatomic, retain) UIImageView * aview;
@ End
@ Implementation RootViewController
-(Id) initWithNibName :( NSString *) nibNameOrNil bundle :( NSBundle *) nibBundleOrNil
{
Self = [superinitWithNibName: nibNameOrNilbundle: nibBundleOrNil];
If (self ){
// Custom initialization
}
Return self;
}
-(Void) viewDidLoad
{
[SuperviewDidLoad];
// Do any additional setup after loading the view.
_ Aview = [[UIImageViewalloc] initWithFrame: CGRectMake (60,100,200,200)];
_ Aview. backgroundColor = [UIColorgrayColor];
[Self. viewaddSubview: _ aview];
// Rotate
_ Aview. userInteractionEnabled = YES; // enable interactive Rotation
UIRotationGestureRecognizer * rotation = [[UIRotationGestureRecognizeralloc] initWithTarget: selfaction: @ selector (handelRotationGesture :)];
[_ AviewaddGestureRecognizer: rotation]; // Add a gesture Reader
[Rotationrelease];
// Kneading
UIPinchGestureRecognizer * pinch = [[UIPinchGestureRecognizeralloc] initWithTarget: selfaction: @ selector (pingchAction :)];
[_ AviewaddGestureRecognizer: pinch];
[Pinchrelease];
// Translation
UIPanGestureRecognizer * pan = [[UIPanGestureRecognizeralloc] initWithTarget: selfaction: @ selector (panAction :)];
[_ AviewaddGestureRecognizer: pan];
[Panrelease];
// Sweep
UISwipeGestureRecognizer * swipe = [[UISwipeGestureRecognizeralloc] initWithTarget: selfaction: @ selector (changeColor :)];
[_ AviewaddGestureRecognizer: swipe];
[Swiperelease];
//-(Void) setTitle :( NSString *) title forSegmentAtIndex :( NSUInteger) segment;
// Add RESPONSE METHOD
[_ AsegmentaddTarget: selfaction: @ selector (handelSegementControlAction :) forControlEvents :( UIControlEventValueChanged)];
_ Asegment. momentary = YES; // after the point is clicked, the button (selected instantly) is NO by default.
[_ AsegmentsetEnabled: NOforSegmentAtIndex: 3]; // unavailable buttons (Gray)
// The slider provides data within the set range. The slider stays at a certain position to obtain a value.
UISlider * slider = [[UISlideralloc] initWithFrame: CGRectMake (60,310,200, 30)];
[Self. viewaddSubview: slider];
[Sliderrelease];
Slider. minimumValue = 0.05;
Slider. maximumValue = 2;
Slider. minimumTrackTintColor = [UIColorredColor];
[Slider addTarget: selfaction: @ selector (handelSliderAction :) forControlEvents :( UIControlEventValueChanged)];
// Play the view animation
NSMutableArray * array = [NSMutableArrayarrayWithCapacity: 40]; // Save the image object
For (int I = 1; I <8; I ++ ){
// The image name. The image name is incorrect. image = nil; 2250_3650903_179fb89ae279fae-% d (dragged). tiff
NSString * name = [NSStringstringWithFormat: @ "2250_3650903_179fb89ae279fae-% d (dragged). tiff", I];
// Create an image
UIImage * image = [UIImageimageNamed: name];
// Add to array
[ArrayaddObject: image];
// UIAlertView
}
_ Aview. animationImages = array;
// [_ Aview startAnimating];
_ Aview. animationDuration = 0.5;
// _ Aview. animationRepeatCount = 2; // The playback is complete in 2 seconds.
[_ AviewstartAnimating];
// _ Aview. animationDuration = 5;
// [_ Aview stopAnimating];
}
// Translation
-(Void) panAction :( UIPanGestureRecognizer *) pan
{
CGPoint panpoint = [pantranslationInView: pan. view];
NSLog (@ "panpoint = % @", NSStringFromCGPoint (panpoint ));
Pan. view. transform = CGAffineTransformMakeTranslation (panpoint. x, panpoint. y );
}
// Kneading
-(Void) pingchAction :( UIPinchGestureRecognizer *) pinch
{
Pinch. view. transform = CGAffineTransformMakeScale (pinch. scale, pinch. scale );
}
// Sweep
-(Void) changeColor :( UISwipeGestureRecognizer *) swipe
{
_ Aview. backgroundColor = [[UIColoralloc] initWithRed: arc4random () % 256/255. 0 green: arc4random () % 256/255. 0 blue: arc4random () % 256/255. 0 alpha: 1.0];
}
// Rotate
-(Void) handelRotationGesture :( UIRotationGestureRecognizer *) rotationGesture
{// Modify the affine Matrix
// _ Aview. transform = CGAffineTransformRotate (_ aview. transform, rotationGesture. rotation );
RotationGesture. view. transform = CGAffineTransformMakeRotation (rotationGesture. rotation );
// RotationGesture. rotation = 0; // reset the rotation angle to zero.
NSLog (@ "rotation = % f", rotationGesture. rotation); // rotation Angle
}
// [Dubai] slider Method
-(Void) handelSliderAction :( UISlider *) slider
{
NSLog (@ "% s" ,__ FUNCTION __);
// Set the current value of the slider to the animation time.
_ Aview. animationDuration = slider. value;
[_ AviewstartAnimating];
}
: