Skip to content

Instantly share code, notes, and snippets.

import UIKit
class ViewController: UIViewController {
var label:UILabel? = nil
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
setupHardCodeLabel()
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self addBottomSheetView];
}
- (void)addBottomSheetView {
BottomSheetViewController *bottomSheetVc = [BottomSheetViewController new];
[self addChildViewController:bottomSheetVc];
[self.view addSubview:bottomSheetVc.view];
- (void)panGesture:(UIPanGestureRecognizer *)recognizer {
// Bottom Sheet 會隨著手勢移動跟著移動
[self moveViewWithGesture:recognizer];
// 當手移開螢幕時,Bottom Sheet 會根據新狀態移動到對應位置
if (recognizer.state != UIGestureRecognizerStateEnded) {
return;
}
// 以動畫效果來漸進畫面的移動
static CGFloat fullViewYPosition = 0;
static CGFloat partialViewYPosition = 0;
static CGFloat expandedViewYPosition = 0;
- (void)setupData {
fullViewYPosition = 100;
partialViewYPosition = [UIScreen mainScreen].bounds.size.height - 130;
expandedViewYPosition = [UIScreen mainScreen].bounds.size.height - 130 - 130;
self.lastStatus = expanded;
- (void)setupGestureEvent {
UIPanGestureRecognizer *gesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGesture:)];
[self.view addGestureRecognizer:gesture];
[self roundViews];
}
- (void)roundViews {
self.view.layer.cornerRadius = 10;
self.view.clipsToBounds = YES;
}
#!/bin/sh
# reference
# https://www.twblogs.net/a/5b8c3b1a2b71771883317c2c
BUILD_RESULT_PATH=build_output
if [ -x nasm ]; then
wget "https://www.nasm.us/pub/nasm/releasebuilds/2.14.03rc2/macosx/nasm-2.14.03rc2-macosx.zip"
unzip nasm-2.14.03rc2-macosx.zip
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "DragDrogCollectionViewCell", for: indexPath) as! DragDrogCollectionViewCell
let index = indexPath.section * ViewController.columnCount + indexPath.row
cell.backgroundColor = UIColor.clear
cell.label.text = ""
if (index < cellDataList.count) {
cell.backgroundColor = UIColor.yellow
cell.label.text = String(cellDataList[index])
}
func updateDataIndex(from fromIndexPath: IndexPath, to toIndexPath: IndexPath) {
let fromPosition = fromIndexPath.item
let toPosition = toIndexPath.item
let selected = cellDataList[fromPosition] as Int
DispatchQueue.main.async {[weak self] in
self?.cellDataList.remove(at: fromPosition)
var newindex = toPosition
if (newindex > self?.cellDataList.count ?? 0) {
newindex = self?.cellDataList.count ?? 0
class ViewController: UIViewController {
func setupCollectionView() {
self.collectionView.collectionViewLayout = columnLayout
self.collectionView.dataSource = self
self.collectionView.dragInteractionEnabled = true
self.collectionView.dragDelegate = self
self.collectionView.dropDelegate = self
}
func updateDataIndex(from fromIndexPath: IndexPath, to toIndexPath: IndexPath) {
func setupCollectionView() {
self.collectionView.collectionViewLayout = columnLayout
self.collectionView.dataSource = self
self.collectionView.dragDelegate = self
self.collectionView.dragInteractionEnabled = true
}
extension ViewController: UICollectionViewDragDelegate {
func collectionView(_ collectionView: UICollectionView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem] {
let attributedString = String(indexPath.item)