Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Mar 16, 2021
1 parent b648688 commit dd4f02f
Show file tree
Hide file tree
Showing 123 changed files with 851 additions and 89 deletions.
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ SwiftUI 示例,技巧和技术集合,帮助我构建应用程序,解决问

响应交互并控制程序状态

- [@ObservedObject@State@EnvironmentObject 有什么区别?](example/state/demo1)
- [如何使用 `@StateObject` 创建和监视外部对象?](example/state/demo2)
- [如何使用 `@ObservedObject` 管理外部对象的状态?](example/state/demo3)
- [如何使用 `@EnvironmentObject` 在视图之间共享数据?](example/state/demo4)
- [如何使用 `objectWillChange` 手动发送状态更新?](example/state/demo5)
- [如何创建常量绑定?](example/state/demo6)
- [如何创建自定义绑定?](example/state/demo7)
- [如何在 SwiftUI 中使用计时器?](example/state/demo8)
- [当使用 `onChange()` 改变状态时如何运行一些代码?](example/state/demo9)
- [@ObservedObject@State@EnvironmentObject 有什么区别?](example/advanced-state/demo1)
- [如何使用 `@StateObject` 创建和监视外部对象?](example/advanced-state/demo2)
- [如何使用 `@ObservedObject` 管理外部对象的状态?](example/advanced-state/demo3)
- [如何使用 `@EnvironmentObject` 在视图之间共享数据?](example/advanced-state/demo4)
- [如何使用 `objectWillChange` 手动发送状态更新?](example/advanced-state/demo5)
- [如何创建常量绑定?](example/advanced-state/demo6)
- [如何创建自定义绑定?](example/advanced-state/demo7)
- [如何在 SwiftUI 中使用计时器?](example/advanced-state/demo8)
- [当使用 `onChange()` 改变状态时如何运行一些代码?](example/advanced-state/demo9)

## 切换界面

Expand Down Expand Up @@ -86,4 +86,6 @@ SwiftUI 示例,技巧和技术集合,帮助我构建应用程序,解决问
- [如何使用 matchedGeometryEffect() 将动画从一个视图同步到另一个视图?](example/animation/demo8)
- [如何通过过渡添加和删除视图?](example/animation/demo9)
- [如何创建不对称过渡?](example/animation/demo10)
- [如何创建自定义过渡?](example/animation/demo11)
- [如何创建自定义过渡?](example/animation/demo11)
- [如何设置文字大小的动画?](example/animation/demo12)
- [如何用事务覆盖动画?](example/animation/demo13)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@
objects = {

/* Begin PBXBuildFile section */
7D3648D625FFD28600C13C01 /* DemoApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D3648D525FFD28600C13C01 /* DemoApp.swift */; };
7D3648D825FFD28600C13C01 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D3648D725FFD28600C13C01 /* ContentView.swift */; };
7D3648DA25FFD28800C13C01 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7D3648D925FFD28800C13C01 /* Assets.xcassets */; };
7D3648DD25FFD28800C13C01 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7D3648DC25FFD28800C13C01 /* Preview Assets.xcassets */; };
7D49905F2600CADF00504434 /* DemoApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D49905E2600CADF00504434 /* DemoApp.swift */; };
7D4990612600CADF00504434 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7D4990602600CADF00504434 /* ContentView.swift */; };
7D4990632600CAE000504434 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7D4990622600CAE000504434 /* Assets.xcassets */; };
7D4990662600CAE000504434 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7D4990652600CAE000504434 /* Preview Assets.xcassets */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
7D3648D225FFD28600C13C01 /* Demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Demo.app; sourceTree = BUILT_PRODUCTS_DIR; };
7D3648D525FFD28600C13C01 /* DemoApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoApp.swift; sourceTree = "<group>"; };
7D3648D725FFD28600C13C01 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
7D3648D925FFD28800C13C01 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
7D3648DC25FFD28800C13C01 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
7D3648DE25FFD28800C13C01 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7D3648DF25FFD28800C13C01 /* Demo.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Demo.entitlements; sourceTree = "<group>"; };
7D49905B2600CADF00504434 /* Demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Demo.app; sourceTree = BUILT_PRODUCTS_DIR; };
7D49905E2600CADF00504434 /* DemoApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoApp.swift; sourceTree = "<group>"; };
7D4990602600CADF00504434 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
7D4990622600CAE000504434 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
7D4990652600CAE000504434 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
7D4990672600CAE000504434 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7D4990682600CAE000504434 /* Demo.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Demo.entitlements; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
7D3648CF25FFD28600C13C01 /* Frameworks */ = {
7D4990582600CADF00504434 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
Expand All @@ -34,121 +34,121 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
7D3648C925FFD28600C13C01 = {
7D4990522600CADF00504434 = {
isa = PBXGroup;
children = (
7D3648D425FFD28600C13C01 /* Demo */,
7D3648D325FFD28600C13C01 /* Products */,
7D49905D2600CADF00504434 /* Demo */,
7D49905C2600CADF00504434 /* Products */,
);
sourceTree = "<group>";
};
7D3648D325FFD28600C13C01 /* Products */ = {
7D49905C2600CADF00504434 /* Products */ = {
isa = PBXGroup;
children = (
7D3648D225FFD28600C13C01 /* Demo.app */,
7D49905B2600CADF00504434 /* Demo.app */,
);
name = Products;
sourceTree = "<group>";
};
7D3648D425FFD28600C13C01 /* Demo */ = {
7D49905D2600CADF00504434 /* Demo */ = {
isa = PBXGroup;
children = (
7D3648D525FFD28600C13C01 /* DemoApp.swift */,
7D3648D725FFD28600C13C01 /* ContentView.swift */,
7D3648D925FFD28800C13C01 /* Assets.xcassets */,
7D3648DE25FFD28800C13C01 /* Info.plist */,
7D3648DF25FFD28800C13C01 /* Demo.entitlements */,
7D3648DB25FFD28800C13C01 /* Preview Content */,
7D49905E2600CADF00504434 /* DemoApp.swift */,
7D4990602600CADF00504434 /* ContentView.swift */,
7D4990622600CAE000504434 /* Assets.xcassets */,
7D4990672600CAE000504434 /* Info.plist */,
7D4990682600CAE000504434 /* Demo.entitlements */,
7D4990642600CAE000504434 /* Preview Content */,
);
path = Demo;
sourceTree = "<group>";
};
7D3648DB25FFD28800C13C01 /* Preview Content */ = {
7D4990642600CAE000504434 /* Preview Content */ = {
isa = PBXGroup;
children = (
7D3648DC25FFD28800C13C01 /* Preview Assets.xcassets */,
7D4990652600CAE000504434 /* Preview Assets.xcassets */,
);
path = "Preview Content";
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
7D3648D125FFD28600C13C01 /* Demo */ = {
7D49905A2600CADF00504434 /* Demo */ = {
isa = PBXNativeTarget;
buildConfigurationList = 7D3648E225FFD28800C13C01 /* Build configuration list for PBXNativeTarget "Demo" */;
buildConfigurationList = 7D49906B2600CAE000504434 /* Build configuration list for PBXNativeTarget "Demo" */;
buildPhases = (
7D3648CE25FFD28600C13C01 /* Sources */,
7D3648CF25FFD28600C13C01 /* Frameworks */,
7D3648D025FFD28600C13C01 /* Resources */,
7D4990572600CADF00504434 /* Sources */,
7D4990582600CADF00504434 /* Frameworks */,
7D4990592600CADF00504434 /* Resources */,
);
buildRules = (
);
dependencies = (
);
name = Demo;
productName = Demo;
productReference = 7D3648D225FFD28600C13C01 /* Demo.app */;
productReference = 7D49905B2600CADF00504434 /* Demo.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */

/* Begin PBXProject section */
7D3648CA25FFD28600C13C01 /* Project object */ = {
7D4990532600CADF00504434 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1240;
LastUpgradeCheck = 1240;
TargetAttributes = {
7D3648D125FFD28600C13C01 = {
7D49905A2600CADF00504434 = {
CreatedOnToolsVersion = 12.4;
};
};
};
buildConfigurationList = 7D3648CD25FFD28600C13C01 /* Build configuration list for PBXProject "Demo" */;
buildConfigurationList = 7D4990562600CADF00504434 /* Build configuration list for PBXProject "Demo" */;
compatibilityVersion = "Xcode 9.3";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 7D3648C925FFD28600C13C01;
productRefGroup = 7D3648D325FFD28600C13C01 /* Products */;
mainGroup = 7D4990522600CADF00504434;
productRefGroup = 7D49905C2600CADF00504434 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
7D3648D125FFD28600C13C01 /* Demo */,
7D49905A2600CADF00504434 /* Demo */,
);
};
/* End PBXProject section */

/* Begin PBXResourcesBuildPhase section */
7D3648D025FFD28600C13C01 /* Resources */ = {
7D4990592600CADF00504434 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
7D3648DD25FFD28800C13C01 /* Preview Assets.xcassets in Resources */,
7D3648DA25FFD28800C13C01 /* Assets.xcassets in Resources */,
7D4990662600CAE000504434 /* Preview Assets.xcassets in Resources */,
7D4990632600CAE000504434 /* Assets.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
7D3648CE25FFD28600C13C01 /* Sources */ = {
7D4990572600CADF00504434 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
7D3648D825FFD28600C13C01 /* ContentView.swift in Sources */,
7D3648D625FFD28600C13C01 /* DemoApp.swift in Sources */,
7D4990612600CADF00504434 /* ContentView.swift in Sources */,
7D49905F2600CADF00504434 /* DemoApp.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */

/* Begin XCBuildConfiguration section */
7D3648E025FFD28800C13C01 /* Debug */ = {
7D4990692600CAE000504434 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
Expand Down Expand Up @@ -209,7 +209,7 @@
};
name = Debug;
};
7D3648E125FFD28800C13C01 /* Release */ = {
7D49906A2600CAE000504434 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
Expand Down Expand Up @@ -263,7 +263,7 @@
};
name = Release;
};
7D3648E325FFD28800C13C01 /* Debug */ = {
7D49906C2600CAE000504434 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
Expand All @@ -287,7 +287,7 @@
};
name = Debug;
};
7D3648E425FFD28800C13C01 /* Release */ = {
7D49906D2600CAE000504434 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
Expand All @@ -314,25 +314,25 @@
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
7D3648CD25FFD28600C13C01 /* Build configuration list for PBXProject "Demo" */ = {
7D4990562600CADF00504434 /* Build configuration list for PBXProject "Demo" */ = {
isa = XCConfigurationList;
buildConfigurations = (
7D3648E025FFD28800C13C01 /* Debug */,
7D3648E125FFD28800C13C01 /* Release */,
7D4990692600CAE000504434 /* Debug */,
7D49906A2600CAE000504434 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
7D3648E225FFD28800C13C01 /* Build configuration list for PBXNativeTarget "Demo" */ = {
7D49906B2600CAE000504434 /* Build configuration list for PBXNativeTarget "Demo" */ = {
isa = XCConfigurationList;
buildConfigurations = (
7D3648E325FFD28800C13C01 /* Debug */,
7D3648E425FFD28800C13C01 /* Release */,
7D49906C2600CAE000504434 /* Debug */,
7D49906D2600CAE000504434 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 7D3648CA25FFD28600C13C01 /* Project object */;
rootObject = 7D4990532600CADF00504434 /* Project object */;
}
50 changes: 50 additions & 0 deletions example/animation/demo12/Demo/Demo/ContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// ContentView.swift
// Demo
//
// Created by 王楚江 on 2021/3/16.
//

import SwiftUI

struct AnimatableSystemFontModifier: AnimatableModifier {
var size: CGFloat
var weight: Font.Weight
var design: Font.Design

var animatableData: CGFloat {
get { size }
set { size = newValue }
}

func body(content: Content) -> some View {
content
.font(.system(size: size, weight: weight, design: design))
}
}

extension View {
func animatableSystemFont(size: CGFloat, weight: Font.Weight = .regular, design: Font.Design = .default) -> some View {
self.modifier(AnimatableSystemFontModifier(size: size, weight: weight, design: design))
}
}

struct ContentView: View {
@State private var fontSize: CGFloat = 32

var body: some View {
Text("Hello, World!")
.animatableSystemFont(size: fontSize)
.onTapGesture {
withAnimation(Animation.spring(response: 0.5, dampingFraction: 0.5, blendDuration: 1).repeatForever()) {
fontSize = 72
}
}
}
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit dd4f02f

Please sign in to comment.