小编Jos*_*ell的帖子

如何在UIView变透明后检测手势?

我有UIView一些其他UI组件来检测长按手势.当长按开始时,我想通过将背景颜色更改为灰色&alpha = 0.1来提示用户.

长按结束后,UIView必须将其更换为完全透明.我把它的alpha设置为0,但问题是......

不能再检测到其他人.

mainView = UIView()
mainView.frame = ...
let longPressRecognizer = UILongPressGestureRecognizer(target: self, action:Selector("longPressed:"))
mainView.addGestureRecognizer(longPressRecognizer)

func longPressed(sender: UILongPressGestureRecognizer) {
    let view = sender.view!

    if sender.state == .Began {
        view.backgroundColor = UIColor.grayColor()
        view.alpha = 0.1
    } else if (sender.state == .Ended || sender.state == .Cancelled || sender.state == .Failed) {
        view.backgroundColor = UIColor.whiteColor()
        view.alpha = 0
    }
}
Run Code Online (Sandbox Code Playgroud)

将此UIView更改回原始状态的正确方法是什么,以便在最初创建时可以检测到其他手势?

cocoa-touch uiview ios swift

1
推荐指数
1
解决办法
334
查看次数

组合多个Bool返回值而不会短路

Swift 2限制了对Bool值使用按位运算符.这是令人愉快的.在ObjC中,当您需要执行每个操作数时使用它非常有用.例如:

a.isFoo() & b.isFoo() & c.isFoo()
Run Code Online (Sandbox Code Playgroud)

在这种情况下,使用按位&将执行每个方法.

如果我使用逻辑运算符&&,它将执行第一个运算符,如果它是false,表达式将返回false而不执行其他两个操作数.

我想找到同样优雅的方式与工作,与Bool斯威夫特.可能吗?

objective-c bitwise-and swift

1
推荐指数
1
解决办法
395
查看次数

从NSString中提取数字

如何从定义如下的字符串中提取数字:

NSString *getNumber = @"Price138.50 Code112.250"
Run Code Online (Sandbox Code Playgroud)

我需要从这个字符串中提取138.50和112.25.

cocoa cocoa-touch nsstring

1
推荐指数
1
解决办法
964
查看次数

为什么没有定义Collections.unmodifiableList来返回List <?扩展T>而不是List <T>?

更改Collections.unmodifiableList为return List<? extends T>而不是List<T>将阻止在编译时添加和删除元素,而不是抛出运行时异常.

是否存在由此替代方案引起的严重问题,从而排除它?

java generics collections

1
推荐指数
1
解决办法
518
查看次数

CGRectGetMidX()和CGRectGetMidY()发生了什么?

我正在关注Rob Percival的SpriteKit教程视频,这行代码无法编译.似乎语法已经过时了,以获得"mid x"和"mid y"值.有哪些替代CGRectGetMidX()和CGRectGetMidY()?

CGPoint(x: CGRectGetMidX(self.frame),y: CGRectGetMidY(self.frame))
Run Code Online (Sandbox Code Playgroud)

core-graphics cgrect swift swift3

1
推荐指数
1
解决办法
2483
查看次数

self.backgroundcolor和self.layer.backgroundcolor之间有什么区别吗?

@implementation AVSuperView

- (AVSuperView*)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
//        self.backgroundColor = [UIColor redColor];
        self.layer.backgroundColor = [[UIColor redColor] CGColor];
        AVLayout* avLayout = [[AVLayout alloc] init];
Run Code Online (Sandbox Code Playgroud)

在上面的自定义UIView中,例如self.backgroundColor和似乎self.layer.backgroundColor相同。是self.backgroundColor包装纸self.layer.backgroundColor吗?

cocoa-touch core-animation ios

1
推荐指数
1
解决办法
238
查看次数

没有参数标签的Swift函数

假设我在 Swift 3 中编写了以下函数:

func rgb(r: CGFloat, g: CGFloat, b: CGFloat) -> UIColor {
    return UIColor.init(red: r, green: g, blue: b, alpha: 1)
}
Run Code Online (Sandbox Code Playgroud)

当我调用它时,我必须写 let black = rgb(r:0, g:0, b:0)

是否可以编写此函数以便我可以将其称为let black = rgb(0, 0, 0)?

syntax swift swift3

1
推荐指数
2
解决办法
3584
查看次数

从设备中查看或检索Core Data .sqlite文件

我怎么能真正在真实设备(而不是模拟器)上看到核心数据存储的.sqlite文件?是否有工具可以让您查看核心数据信息?

core-data ios

1
推荐指数
1
解决办法
545
查看次数

在presentViewController之后不显示导航栏

嗨,我使用此代码仅使用代码而不使用 segue 移入新的控制器。

    UIStoryboard * mainstoryb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController * vc = [mainstoryb instantiateViewControllerWithIdentifier:@"online_shop"];
[self presentViewController:vc animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

如何在下一个视图中显示导航栏或标题栏?

objective-c uinavigationbar ios presentviewcontroller

1
推荐指数
1
解决办法
6252
查看次数

每天在特定时间在后台从 iOS 调用 Web 服务

有没有办法安排每天在特定时间调用 Web 服务的函数?

根据我的研究,我将不得不使用本地通知或NSTimer在特定时间安排或调用该功能。但是,无论我的应用程序是在计划时间处于后台(并且不运行任何后台任务)还是在前台,我都需要它来工作。

有两种情况: 1. 我的应用程序在后台运行位置服务 2. 没有位置或后台服务正在运行,或者应用程序处于挂起状态(如果用户禁用了位置更新)

但是我必须每天在预定时间向我的服务器发送一些状态。

cocoa-touch ios background-task

1
推荐指数
1
解决办法
628
查看次数