맞춤 블록 드래그 전략
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
블록 드래그 전략은 블록의 처리 방식을 결정하는 객체입니다.
드래그 블록을 드래그 가능하도록 하는 로직을 구현합니다.
새 블록 드래그 전략을 만들면 맞춤 선택 가능한 항목을 만들거나 선택을 처리하지 않고도 블록이 드래그를 처리하는 방식을 전환할 수 있습니다.
예를 들어 블록을 평소와 같이 드래그하는 대신 드래그할 때 블록을 복제하려고 할 수 있습니다. 차단 드래그 전략을 사용하면 가능합니다.
드래그 전략에는 getRelativeToSurfaceXY
메서드를 제외하고 IDraggable
와 동일한 메서드가 모두 있습니다.
구현
드래그 전략을 만들려면
IDragStrategy
인터페이스 이를 위해서는
IDraggable
인터페이스로 사용(getRelativeToSurfaceXY
메서드 제외)
이는 블록이 이미 구현하고 있습니다.
드래그 가능한 요소 구현 안내에 따라 드래그 전략을 구현할 수 있지만 getRelativeToSurfaceXY()
구현은 건너뜁니다.
사용
맞춤 드래그 전략을 사용하려면 각 항목에 드래그 전략을 적용해야 합니다.
인스턴스를 반환합니다. 블록의 init
메서드에서 setDragStrategy
를 호출하여 이를 실행할 수 있습니다.
Blockly.Blocks['my_block'] = {
init: function() {
// Other initialization...
this.setDragStrategy(new MyDragStrategy());
// Other initialization...
}
}
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-25(UTC)
[null,null,["최종 업데이트: 2025-07-25(UTC)"],[],["Block drag strategies dictate how a block behaves during drags, allowing for custom drag behaviors like duplication. Developers implement the `IDragStrategy` interface, which mirrors `IDraggable` methods except for `getRelativeToSurfaceXY`. To apply a custom strategy, use the `setDragStrategy` method within a block's `init` method. This enables switching block drag behavior without altering core selection or drag handling. You must implement all the methods of `IDraggable` in the custom strategy except for `getRelativeToSurfaceXY`.\n"],null,[]]