Use of various iOS gestures and UISlider

Source: Internet
Author: User

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];

}


:



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.