연구 설문조사: Blockly 사용 경험을 알려주세요
설문조사 시작
드래그 전략 차단
블록 드래그 전략은 블록이 드래그를 처리하는 방법을 결정하는 객체입니다. 블록을 드래그 가능하게 만드는 로직을 구현합니다.
새 블록 드래그 전략을 만들면 맞춤 선택 가능 항목을 만들거나 선택을 처리할 필요 없이 블록에서 드래그를 처리하는 방법을 전환할 수 있습니다.
예를 들어 블록을 정상적으로 드래그하는 대신 드래그 시 복제하도록 할 수 있습니다. 드래그 차단 전략을 사용하면 가능합니다.
드래그 전략에는 getRelativeToSurfaceXY
메서드 외에 IDraggable
와 동일한 메서드가 모두 있습니다.
구현
드래그 전략을 만들려면 IDragStrategy
인터페이스를 구현해야 합니다. 이를 위해서는 블록에서 이미 구현한 getRelativeToSurfaceXY
메서드를 제외하고 IDraggable
인터페이스와 동일한 메서드가 모두 필요합니다.
드래그 가능한 구현 안내에 따라 드래그 전략을 구현할 수 있지만 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 계열사의 등록 상표입니다.
최종 업데이트: 2024-04-12(UTC)
[null,null,["최종 업데이트: 2024-04-12(UTC)"],[[["Block drag strategies dictate how blocks respond to drag events, offering an alternative to custom selectables."],["By implementing the `IDragStrategy` interface, developers can create custom drag behaviors like block duplication on drag."],["Drag strategies encompass the functionality of `IDraggable`, excluding the `getRelativeToSurfaceXY` method, which is handled internally by the block."],["Applying a custom drag strategy requires using `setDragStrategy` within the block's `init` method to associate the strategy with each block instance."]]],["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"]]