Skip to content

Instantly share code, notes, and snippets.

View SongJiaqiang's full-sized avatar
🌴
On vacation

Jarvis SongJiaqiang

🌴
On vacation
View GitHub Profile
// show image
self.imageView.image = [UIImage imageNamed:@"imagename"];
// create effect
UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
// add effect to an effect view
UIVisualEffectView *effectView = [[UIVisualEffectView alloc]initWithEffect:blur];
effectView.frame = self.view.frame;
@SongJiaqiang
SongJiaqiang / flipImage.m
Last active November 28, 2016 12:02
flip UIImage
// 直接翻转UIImageView
func flipImageView(imageView: UIView) {
imageView.transform = CGAffineTransform(scaleX: -1, y: 1)
}
// 修改imageOrientation属性, 这个方法只适用于UIKit中显示的image
func flipImage(originImage: UIImage) -> UImage {
let cgImage = originImage.cgImage!
let flipedImage = UIImage(cgImage: originImage,
@SongJiaqiang
SongJiaqiang / NavigationController.swift
Last active July 19, 2017 17:04
1. Enable pan edge to pop view controller. 2. Queue popping and pushing actions.
//
// NavigationController.swift
// EvoRadio
//
// Created by Jarvis on 16/4/17.
// Copyright © 2016年 JQTech. All rights reserved.
//
import UIKit
@SongJiaqiang
SongJiaqiang / ShareVideoWithActivityView.m
Created December 2, 2016 07:56
使用UIActivityViewController分享视频
- (void)shareVideo {
NSString *videoPath = @"xxx/xxx/test.mp4";
NSURL *shareURL = [NSURL fileURLWithPath:videoPath];
NSString *shareMessage = @"Hey! Here is an interesting video. #Tag";
NSArray *shareItems = @[shareMessage, shareURL];
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:shareItems applicationActivities:nil];
[self presentViewController:controller animated:YES completion:nil];
}
- (UIImage *)fixImageOrientation {
UIImageOrientation originOrientation = self.imageOrientation;
// No-op if the orientation is already correct
if (originOrientation == UIImageOrientationUp) return self;
// We need to calculate the proper transformation to make the image upright.
// We do it in 2 steps: Rotate if Left/Right/Down, and then flip if Mirrored.
CGAffineTransform transform = CGAffineTransformIdentity;
func drawPDFfromURL(url: URL) -> UIImage? {
guard let document = CGPDFDocument(url as CFURL) else { return nil }
guard let page = document.page(at: 1) else { return nil }
let pageRect = page.getBoxRect(.mediaBox)
let renderer = UIGraphicsImageRenderer(size: pageRect.size)
let img = renderer.image { ctx in
UIColor.white.set()
ctx.fill(pageRect)
@SongJiaqiang
SongJiaqiang / gif.swift
Last active October 16, 2019 05:39
保存gif到相册
import AssetsLibrary
import MobileCoreServices
/// 保存gif图到相册
func saveGif2Album() {
let gifPath = Bundle.main.path(forResource: "name", ofType: "gif")
let gifData = NSData(contentsOfFile: gifPath!) as Data
let library = ALAssetsLibrary()
// Create a UIImage from sample buffer data
- (UIImage *) imageFromSampleBuffer:(CMSampleBufferRef) sampleBuffer {
// Get a CMSampleBuffer's Core Video image buffer for the media data
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
// Lock the base address of the pixel buffer
CVPixelBufferLockBaseAddress(imageBuffer, 0);
// Get the number of bytes per row for the pixel buffer
void *baseAddress = CVPixelBufferGetBaseAddress(imageBuffer);
@SongJiaqiang
SongJiaqiang / OpenAppStoreWithAppID.m
Created April 27, 2018 08:20
打开app在appstore的介绍页面
/** 跳转AppStore app */
- (void)goAppStore:(NSString *)appId {
if (!appId || appId.length == 0) {
logError(@">> TTAD: AppId不能为空");
return;
}
logInfo(@">> TTAD: 跳转到内置appstore页: %@", appId);
NSString *urlStr = [NSString stringWithFormat:@"https://itunes.apple.com/cn/app/id%@", appId];
NSURL *openURL = [NSURL URLWithString:urlStr];
@SongJiaqiang
SongJiaqiang / OpenAppStoreWithAppID.m
Created April 27, 2018 08:20
打开app在appstore的介绍页面
/** 跳转AppStore app */
- (void)goAppStore:(NSString *)appId {
if (!appId || appId.length == 0) {
logError(@">> TTAD: AppId不能为空");
return;
}
logInfo(@">> TTAD: 跳转到内置appstore页: %@", appId);
NSString *urlStr = [NSString stringWithFormat:@"https://itunes.apple.com/cn/app/id%@", appId];
NSURL *openURL = [NSURL URLWithString:urlStr];