小编JuJ*_*oDi的帖子

相对于开始拖动位置HTML5,Ember跟踪鼠标

从这个小提琴开始,我想输出可拖动对象的坐标,因为它被拖动,相对于它的起始位置,它总是{0,0}.我知道我可以记录开始和结束拖动事件,如:

DragNDrop.Draggable = Ember.Mixin.create({
    attributeBindings: 'draggable',
    draggable: 'true',
    dragStart: function(event) {
        var dataTransfer = event.originalEvent.dataTransfer;
        dataTransfer.setData('Text', this.get('elementId'));
        console.log('begin coordinates: (0, 0)');
    },
    dragEnd: function(event) {
        console.log('end coordinates');  
    }
});
Run Code Online (Sandbox Code Playgroud)

所以我有两个问题:

1.如何获得鼠标坐标?

2.如何调用dragEnd函数,如何继续输出鼠标坐标?

编辑:

对于1.我现在可以使用以下方法获取鼠标坐标:

DragNDrop.Draggable = Ember.Mixin.create({
    attributeBindings: 'draggable',
    draggable: 'true',
    dragStart: function(event) {
        var dataTransfer = event.originalEvent.dataTransfer;
        dataTransfer.setData('Text', this.get('elementId'));
        console.log('begin coordinates: ', event.originalEvent.pageX, event.originalEvent.pageY);
    },
    dragEnd: function(event) {
        console.log('end coordinates: ', event.originalEvent.pageX, event.originalEvent.pageY);  
    }
});
Run Code Online (Sandbox Code Playgroud)

但是我仍然不确定如何连续输出当前鼠标坐标,而不是仅在拖动开始时和拖动结束时输出一次.

javascript css jquery html5 ember.js

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

Swift - 期望'{'启动setter定义

我正在关注高级swift WWDC 2014视频,使用类上的下标委托给一个类属性,但是我使用与视频相同的语法收到错误

enum Direction {
    case North, South, East, West
}

class Place: Thing {
    init (_ location: Thing?, _ name: String, _ longDescription: String) {
        self.exits = Dictionary<Direction, Place> ()
        super.init(location, name, longDescription)
    }
    var exits: Dictionary<Direction, Place>
}

extension Place {
    subscript(direction: Direction) -> Place? {
        get {
            return exits[direction]
        }
        set (destination: Place?) { // error here
            exits[direction] = destination
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我得到的错误是

Expected '{' to start setter definition
Run Code Online (Sandbox Code Playgroud)

swift

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

如何在Swift中获得CConstPointer?

我想用变换转换CGPath,CGAffineTransformMakeRotation(radians)CGPathCreateCopyByTransformingPathfunc需要一个CConstPointer<CGAffineTransform>.我该如何CConstPointer<CGAffineTransform>摆脱我的CGAffineTransform

cgaffinetransform const-pointer swift

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

无法识别的选择器发送到类[NSCalendar calendarWithIdentifier]

我有一个用Swift编写的应用程序,它在iOS模拟器上运行良好.该项目的目标设置为iOS 7.1.

当我在iPhone 5s上运行应用程序时,它崩溃在以下行:

let calendar = NSCalendar(identifier: NSGregorianCalendar)
Run Code Online (Sandbox Code Playgroud)

有错误:

+[NSCalendar calendarWithIdentifier:]: unrecognized selector sent to class 0x1955eee60
Run Code Online (Sandbox Code Playgroud)

我是否必须针对iOS8与iOS7.x进行不同的调用?

nscalendar ios unrecognized-selector swift

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

将元组附加到元组数组

我的类声明了一个数组

var laps: (start: NSDate!, end: NSDate!)[] = []
Run Code Online (Sandbox Code Playgroud)

当一个元组添加到这个数组时,我希望能够做类似的事情

let now = NSDate()
var lap = (now, nil)
laps.append(lap)
Run Code Online (Sandbox Code Playgroud)

但在append我得到错误Missing argument for parameter 'end' in call.

optional swift

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

使用PHP中的preg_match提取价格

我有一个字符串,从file_get_contents()调用,包含如下内容:

    <span class="cb_price_countdown cb_lot_price_1439066">$40.65</span>
Run Code Online (Sandbox Code Playgroud)

我想提取价格40.65.我不熟悉正则表达式或preg_match所以我很难过.到目前为止,我尝试过:

    $pattern = "/\\\$?((\d{1,3}(,\d{3})*)|(\d+))(\.\d{2})?$/";
    preg_match ($pattern, $subject, $matches);
    print_r ($matches);
Run Code Online (Sandbox Code Playgroud)

哪个没有返回任何有用的东西,我试过:

    $pattern = "/[\d+|\d+,\d+]\.\d{0,2}/";
Run Code Online (Sandbox Code Playgroud)

但这是同一个故事.有人可以告诉我正在寻找的正确的preg_match模式吗?

谢谢你,
贾斯汀

php regex preg-match

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

AVCaptureSession输出未正确显示,并且未调用AVCaptureMetadataOutputObjectsDelegate方法

我有一个单一的视图应用程序,我试图根据这个解释测试iOS7的AVCaptureMetadataOutput .我的ViewController符合AVCaptureMetadataOutputObjectsDelegate并且代码看起来像这样(几乎与Mattt的相同):

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    // Testing the VIN Scanner before I make it part of the library
    NSLog(@"Setting up the vin scanner");
    AVCaptureSession *session = [[AVCaptureSession alloc] init];
    AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    NSError *error = nil;

    AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device
                                                                        error:&error];
    if (input) {
        [session addInput:input];
    } else {
        NSLog(@"Error: %@", error);
    }

    AVCaptureMetadataOutput *output = [[AVCaptureMetadataOutput alloc] …
Run Code Online (Sandbox Code Playgroud)

avfoundation ios avcapturesession ios7

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

如何将diff应用于源代码?

有人发给我遥控器和本地遥控器的输出.我的本地是遥控器的克隆,没有任何变化.将diff应用于我的本地而不需要手动完成并进行每次更改的最佳方法是什么?

diff --git a/path b/path
Run Code Online (Sandbox Code Playgroud)

git diff

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