Skip to content

Instantly share code, notes, and snippets.

View SongJiaqiang's full-sized avatar
🌴
On vacation

Jarvis SongJiaqiang

🌴
On vacation
View GitHub Profile
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)
- (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;
@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];
}
@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 / 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,
// 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 / DeleteFileFromDocument.m
Created November 23, 2016 01:54
delete file from document directory.
- (void)removeFile:(NSString *)filename
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filePath = [documentsPath stringByAppendingPathComponent:filename];
NSError *error;
BOOL success = [fileManager removeItemAtPath:filePath error:&error];
if (success) {
UIAlertView *removedSuccessFullyAlert = [[UIAlertView alloc] initWithTitle:@"Congratulations:" message:@"Successfully removed" delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil];
- (NSString *)jsonFromDictionary:(NSDictionary *)dict {
NSDictionary *plistDict = nil;
if (dict != nil) {
plistDict = dict;
}else {
NSString *path = [[NSBundle mainBundle] pathForResource:@"items.plist" ofType:nil];
NSArray *array = [NSArray arrayWithContentsOfFile:path];
plistDict = [NSDictionary dictionaryWithObject:array forKey:@"list"];
}
@SongJiaqiang
SongJiaqiang / AuthorizationTool.h
Created November 2, 2016 04:11
iOS9 之后需要用户手动授予app权限,这段代码简化了请求权限的代码书写。暂时支持相机、相册、麦克风,其它权限以后再加。
//
// AuthorizationTool.h
// Rokk
//
// Created by Jarvis on 01/11/2016.
// Copyright © 2016 JQTech. All rights reserved.
//
#import <Foundation/Foundation.h>
@SongJiaqiang
SongJiaqiang / TwitterVideoUpload.m
Created October 19, 2016 08:31
Share video to Twitter with System Social framework
#import <Foundation/Foundation.h>
#import <Social/Social.h>
#import <Accounts/Accounts.h>
typedef void(^VideoUploadCompletion)(BOOL success, NSString *errorMessage);
typedef void(^ResultAccount)(ACAccount *account);
@interface SocialVideoHelper : NSObject
+(void)getFirstTwitterAccount:(ResultAccount)complete;