Skip to content

Commit

Permalink
[FEAT] Spacing를 제외한 구현(#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
YoonAh-dev committed Jul 1, 2021
1 parent 7fc7884 commit 1183151
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "2D.pdf",
"idiom" : "universal"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
import UIKit

class CarouselLayout: UICollectionViewFlowLayout {
public var sideItemScale: CGFloat = 2
public var sideItemAlpha: CGFloat = 0.5
public var sideItemScale: CGFloat = 0.5
public var sideItemAlpha: CGFloat = 1
public var spacing: CGFloat = 10

public var isPagingEnabled: Bool = false

private var isSetup: Bool = false

private let itemSizeWidth: CGFloat = 115
private let itemSizeHeight: CGFloat = 98

override public func prepare() {
super.prepare()
if isSetup == false {
Expand All @@ -29,12 +32,12 @@ class CarouselLayout: UICollectionViewFlowLayout {

let collectionViewSize = collectionView.bounds.size

let xInset = (collectionViewSize.width - self.itemSize.width) / 2
let yInset = (collectionViewSize.height - self.itemSize.height) / 2
let xInset = (collectionViewSize.width - itemSizeWidth) / 2
let yInset = (collectionViewSize.height - itemSizeHeight) / 7

self.sectionInset = UIEdgeInsets(top: yInset, left: xInset, bottom: yInset, right: xInset)

let itemWidth = self.itemSize.width * 2
let itemWidth = itemSizeWidth

let scaledItemOffset = (itemWidth - itemWidth*self.sideItemScale) / 2
self.minimumLineSpacing = spacing - scaledItemOffset
Expand Down Expand Up @@ -62,7 +65,7 @@ class CarouselLayout: UICollectionViewFlowLayout {
let contentOffset = collectionView.contentOffset.x
let center = attributes.center.x - contentOffset

let maxDistance = self.itemSize.width + self.minimumLineSpacing
let maxDistance = itemSizeWidth + self.minimumLineSpacing
let distance = min(abs(collectionCenter - center), maxDistance)

let ratio = (maxDistance - distance)/maxDistance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,7 @@ extension ViewController: UICollectionViewDataSource {
}

extension ViewController: UICollectionViewDelegateFlowLayout {

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: 115, height: 98)
}
}
19 changes: 13 additions & 6 deletions YoonAh-dev/CarouselEffectTest/CarouselEffectTest/testCVC.xib
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand All @@ -16,16 +15,24 @@
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
<rect key="frame" x="0.0" y="0.0" width="181" height="146"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="2D" translatesAutoresizingMaskIntoConstraints="NO" id="bg8-my-T4D">
<rect key="frame" x="0.0" y="0.0" width="181" height="146"/>
</imageView>
</subviews>
</view>
<viewLayoutGuide key="safeArea" id="ZTg-uK-7eu"/>
<color key="backgroundColor" systemColor="systemPurpleColor"/>
<constraints>
<constraint firstAttribute="trailing" secondItem="bg8-my-T4D" secondAttribute="trailing" id="Cqu-5i-g12"/>
<constraint firstItem="bg8-my-T4D" firstAttribute="top" secondItem="gTV-IL-0wX" secondAttribute="top" id="cPA-4m-Vbb"/>
<constraint firstAttribute="bottom" secondItem="bg8-my-T4D" secondAttribute="bottom" id="hYI-jH-UFt"/>
<constraint firstItem="bg8-my-T4D" firstAttribute="leading" secondItem="gTV-IL-0wX" secondAttribute="leading" id="mdt-gH-dr6"/>
</constraints>
<size key="customSize" width="181" height="146"/>
<point key="canvasLocation" x="197.82608695652175" y="172.76785714285714"/>
<point key="canvasLocation" x="38" y="48"/>
</collectionViewCell>
</objects>
<resources>
<systemColor name="systemPurpleColor">
<color red="0.68627450980392157" green="0.32156862745098042" blue="0.87058823529411766" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<image name="2D" width="135" height="116"/>
</resources>
</document>

0 comments on commit 1183151

Please sign in to comment.