示例#1
0
void scroll_layer_set_content_offset(ScrollLayer *l, GPoint offset, bool animated) {
    SCROLL_GET;
    if (gpoint_equal(&scroll->content_sublayer->frame.origin,&offset))
        return;
    offset.x=0;
    GPoint oldOffset=scroll_layer_get_content_offset(l);
    GRect to=scroll_layer_get_new_content_rect(l,offset);
    if (animated) {
        if (scroll->animation)
            property_animation_destroy(scroll->animation);
        scroll->animation=property_animation_create_layer_frame(scroll->content_sublayer,0,&to);
        double duration=to.origin.y-oldOffset.y;
        if (duration<25||duration>-25)
            duration=abs(duration)*SCROLL_LAYER_SCROLL_SPEED;
        else
            duration=1;
        animation_set_duration((Animation*)scroll->animation,duration);
        animation_schedule((Animation*)scroll->animation);
    }
    else {
        scroll->content_sublayer->frame.origin=offset;
        layer_mark_dirty(scroll_layer);
    }
    if (scroll->callbacks.content_offset_changed_handler!=0)
        scroll->callbacks.content_offset_changed_handler(l,scroll->context);
}
示例#2
0
void layer_move(Layer *layer, int x, int y) {
    GRect frame = layer_get_frame(layer);
    GPoint point = GPoint(x, y);

    if (!gpoint_equal(&frame.origin, &point)) {
        frame.origin = point;
        layer_set_frame(layer, frame);
    }
}