IOS realizes picture dithering effect

Time:2021-7-29

This example shares the specific code of IOS to realize the image dithering effect for your reference. The specific contents are as follows

design sketch:

Core code:

//
// ViewController.m
//Icon jitter
//
// Created by llkj on 2017/8/29.
// Copyright  ©  2017 laynecheung. All rights reserved
//

#import "ViewController.h"

#define angle2Rad(angle) ((angle) / 180.0 *M_PI)

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *imageV;
@end

@implementation ViewController

- (void)viewDidLoad {
 [super viewDidLoad];

 self.imageV.userInteractionEnabled = YES;
 //Add long press gesture
 UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];

 [self.imageV addGestureRecognizer:longPress];
}

- (void)longPress:(UILongPressGestureRecognizer *)longPress{

 //Create animated objects
 CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];

 anim.keyPath = @"transform.rotation";
 anim.values = @[@(angle2Rad(-5)),@(angle2Rad(5))];
 anim.repeatCount = MAXFLOAT;
// anim.duration = 1;
 anim.autoreverses = YES;


 [self.imageV.layer addAnimation:anim forKey:nil];

}

- (void)didReceiveMemoryWarning {
 [super didReceiveMemoryWarning];
 // Dispose of any resources that can be recreated.
}


@end

Xiaobian will add a section of implementation code for IOS uiview view view jitter effect:

/**
 *Dithering effect
 *
 *@ param VIEWview to shake
 */
- (void)shakeAnimationForView:(UIView *) view {
 CALayer *viewLayer = view.layer;
 CGPoint position = viewLayer.position;
 CGPoint x = CGPointMake(position.x + 1, position.y);
 CGPoint y = CGPointMake(position.x - 1, position.y);
 CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
 [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
 [animation setFromValue:[NSValue valueWithCGPoint:x]];
 [animation setToValue:[NSValue valueWithCGPoint:y]];
 [animation setAutoreverses:YES];
 [animation setDuration:.06];
 [animation setRepeatCount:3];
 [viewLayer addAnimation:animation forKey:nil];
}

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support developpaer.

Recommended Today

VBS obtains the operating system and its version number

VBS obtains the operating system and its version number ? 1 2 3 4 5 6 7 8 9 10 11 12 ‘************************************** ‘*by r05e ‘* operating system and its version number ‘************************************** strComputer = “.” Set objWMIService = GetObject(“winmgmts:” _  & “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2”) Set colOperatingSystems = objWMIService.ExecQuery _  (“Select * from […]