关闭

iOS 3D touch 开发

标签: ios3dapplication应用
111人阅读 评论(0) 收藏 举报
分类:

1.在AppDelegate.m中添加方法,在6s设备上实现了弹出小窗口的效果,点击默认打开应用程序,但是不会执行相关方法

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

    

    

    UIApplicationShortcutItem *itme1 = [[UIApplicationShortcutItemalloc]initWithType:@"能行不66"localizedTitle:@"能行不"];

    UIApplicationShortcutItem *itme2 = [[UIApplicationShortcutItemalloc]initWithType:@"我了擦66"localizedTitle:@"我了擦"];

    UIApplicationShortcutItem *itme3 = [[UIApplicationShortcutItemalloc]initWithType:@"王八蛋66"localizedTitle:@"王八蛋"];

    

    NSArray *array = @[itme1,itme2,itme3];

    

    [UIApplicationsharedApplication].shortcutItems = array;

    

    return YES;

}

2.在AppDelegate.m中添加如下回掉方法,可以判断点击按钮

- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler{

   

    if ([shortcutItem.localizedTitleisEqualToString:@"王八蛋"]) {

        UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"王八蛋"message:@" 是王慧"delegate:selfcancelButtonTitle:@"好的"otherButtonTitles:nil,nil];

        

        [alert show];

    }

    

    NSLog(@"%@",shortcutItem.localizedTitle);

    

}

自此你已经能够通过对桌面上应用图标进行按压手势的了,会弹出一个小窗口,显示 shortcutItems



下面这段代码写在ViewController中,实现的是一个简单的画板功能,它可以根据你按压的力度自动调节画笔的宽度


@interface ViewController ()

{

    CGPoint touchPoint;  //手指的位置

    UIImageView *canDraw;  //画布图片

}

@end


通过touchesBegan 和 touchesMoved 的方法实现画布的功能

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event

{

    UITouch *touch = [touches anyObject];

    touchPoint = [touch locationInView:canDraw];

}


- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event

{

    UITouch *touch = [touches anyObject];

    CGPoint currentPoint = [touch locationInView:canDraw];

    

    UIGraphicsBeginImageContext(canDraw.frame.size);

    [canDraw.image drawInRect:CGRectMake(0.0, 0.0, canDraw.frame.size.width, canDraw.frame.size.height)];

    

    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);

    

    float lineWidthc = 10.0;


//这个就是力度啦~~~~

    if ([touch respondsToSelector:@selector(force)]) {

        NSLog(@"force:%f", touch.force);

        lineWidthc = lineWidthc * touch.force;

    }

    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), lineWidthc);

    

    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.0, 0.0, 1.0);

    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), touchPoint.x, touchPoint.y);

    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);

    CGContextStrokePath(UIGraphicsGetCurrentContext());

    canDraw.image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    

    touchPoint = currentPoint;

    

}



本文是整理XXX的demo写的,十分感谢XXX的demo,不过不好意思忘了当时在哪下载的,也忘了您的大名了!

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1478次
    • 积分:44
    • 等级:
    • 排名:千里之外
    • 原创:3篇
    • 转载:0篇
    • 译文:0篇
    • 评论:0条
    文章分类
    文章存档