![Alamofire: Elegant Networking in Swift](https://raw.githubusercontent.com/Alamofire/Alamofire/master/Resources/AlamofireLogo.png)
[![Swift](https://img.shields.io/badge/Swift-5.1_5.2_5.3_5.4-orange?style=flat-square)](https://img.shields.io/badge/Swift-5.1_5.2_5.3_5.4-Orange?style=flat-square)
[![Platforms](https://img.shields.io/badge/Platforms-macOS_iOS_tvOS_watchOS_Linux_Windows-yellowgreen?style=flat-square)](https://img.shields.io/badge/Platforms-macOS_iOS_tvOS_watchOS_Linux_Windows-Green?style=flat-square)
[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/Alamofire.svg?style=flat-square)](https://img.shields.io/cocoapods/v/Alamofire.svg)
[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat-square)](https://github.com/Carthage/Carthage)
[![Swift Package Manager](https://img.shields.io/badge/Swift_Package_Manager-compatible-orange?style=flat-square)](https://img.shields.io/badge/Swift_Package_Manager-compatible-orange?style=flat-square)
[![Twitter](https://img.shields.io/badge/twitter-@AlamofireSF-blue.svg?style=flat-square)](https://twitter.com/AlamofireSF)
[![Swift Forums](https://img.shields.io/badge/Swift_Forums-Alamofire-orange?style=flat-square)](https://forums.swift.org/c/related-projects/alamofire/37)
Alamofire is an HTTP networking library written in Swift.
- [Features](#features)
- [Component Libraries](#component-libraries)
- [Requirements](#requirements)
- [Migration Guides](#migration-guides)
- [Communication](#communication)
- [Installation](#installation)
- [Usage](https://github.com/Alamofire/Alamofire/blob/master/Documentation/Usage.md#using-alamofire)
- [**Introduction -**](https://github.com/Alamofire/Alamofire/blob/master/Documentation/Usage.md#introduction) [Making Requests](https://github.com/Alamofire/Alamofire/blob/master/Documentation/Usage.md#making-requests), [Response Handling](https://github.com/Alamofire/Alamofire/blob/master/Documentation/Usage.md#response-handling), [Response Validation](https://github.com/Alamofire/Alamofire/blob/master/Documentation/Usage.md#response-validation), [Response Caching](https://github.com/Alamofire/Alamofire/blob/master/Documentation/Usage.md#response-caching)
- **HTTP -** [HTTP Methods](https://github.com/Alamofire/Alamofire/blob/master/Documentation/Usage.md#http-methods), [Parameters and Parameter Encoder](https://github.com/Alamofire/Alamofire/blob/master/Documentation/Usage.md##request-parameters-and-parameter-encoders), [HTTP Headers](https://github.com/Alamofire/Alamofire/blob/master/Documentation/Usage.md#http-headers), [Authentication](https://github.com/Alamofire/Alamofire/blob/master/Documentation/Usage.md#authentication)
- **Large Data -** [Downloading Data to a File](https://github.com/Alamofire/Alamofire/blob/master/Documentation/Usage.md#downloading-data-to-a-file), [Uploading Data to a Server](https://github.com/Alamofire/Alamofire/blob/master/Documentation/Usage.md#uploading-data-to-a-server)
- **Tools -** [Statistical Metrics](https://github.com/Alamofire/Alamofire/blob/master/Documentation/Usage.md#statistical-metrics), [cURL Command Output](https://github.com/Alamofire/Alamofire/blob/master/Documentation/Usage.md#curl-command-output)
- [Advanced Usage](https://github.com/Alamofire/Alamofire/blob/master/Documentation/AdvancedUsage.md)
- **URL Session -** [Session Manager](https://github.com/Alamofire/Alamofire/blob/master/Documentation/AdvancedUsage.md#session), [Session Delegate](https://github.com/Alamofire/Alamofire/blob/master/Documentation/AdvancedUsage.md#sessiondelegate), [Request](https://github.com/Alamofire/Alamofire/blob/master/Documentation/AdvancedUsage.md#request)
- **Routing -** [Routing Requests](https://github.com/Alamofire/Alamofire/blob/master/Documentation/AdvancedUsage.md#routing-requests), [Adapting and Retrying Requests](https://github.com/Alamofire/Alamofire/blob/master/Documentation/AdvancedUsage.md#adapting-and-retrying-requests-with-requestinterceptor)
- **Model Objects -** [Custom Response Handlers](https://github.com/Alamofire/Alamofire/blob/master/Documentation/AdvancedUsage.md#customizing-response-handlers)
- **Connection -** [Security](https://github.com/Alamofire/Alamofire/blob/master/Documentation/AdvancedUsage.md#security), [Network Reachability](https://github.com/Alamofire/Alamofire/blob/master/Documentation/AdvancedUsage.md#network-reachability)
- [Open Radars](#open-radars)
- [FAQ](#faq)
- [Credits](#credits)
- [Donations](#donations)
- [License](#license)
## Features
- [x] Chainable Request / Response Methods
- [x] Combine Support
- [x] URL / JSON Parameter Encoding
- [x] Upload File / Data / Stream / MultipartFormData
- [x] Download File using Request or Resume Data
- [x] Authentication with `URLCredential`
- [x] HTTP Response Validation
- [x] Upload and Download Progress Closures with Progress
- [x] cURL Command Output
- [x] Dynamically Adapt and Retry Requests
- [x] TLS Certificate and Public Key Pinning
- [x] Network Reachability
- [x] Comprehensive Unit and Integration Test Coverage
- [x] [Complete Documentation](https://alamofire.github.io/Alamofire)
## Component Libraries
In order to keep Alamofire focused specifically on core networking implementations, additional component libraries have been created by the [Alamofire Software Foundation](https://github.com/Alamofire/Foundation) to bring additional functionality to the Alamofire ecosystem.
- [AlamofireImage](https://github.com/Alamofire/AlamofireImage) - An image library including image response serializers, `UIImage` and `UIImageView` extensions, custom image filters, an auto-purging in-memory cache, and a priority-based image downloading system.
- [AlamofireNetworkActivityIndicator](https://github.com/Alamofire/AlamofireNetworkActivityIndicator) - Controls the visibility of the network activity indicator on iOS using Alamofire. It contains configurable delay timers to help mitigate flicker and can support `URLSession` instances not managed by Alamofire.
## Requirements
| Platform | Minimum Swift Version | Installation | Status |
| --- | --- | --- | --- |
| iOS 10.0+ / macOS 10.12+ / tvOS 10.0+ / watchOS 3.0+ | 5.1 | [CocoaPods](#cocoapods), [Carthage](#carthage), [Swift Package Manager](#swift-package-manager), [Manual](#manually) | Fully Tested |
| Linux | Latest Only | [Swift Package Manager](#swift-package-manager) | Building But Unsupported |
| Windows | Latest Only | [Swift Package Manager](#swift-package-manager) | Building But Unsupported |
#### Known Issues on Linux and Windows
Alamofire builds on Linux and Windows but there are missing features and many issues in the underlying `swift-corelibs-foundation` that prevent full functionality and may cause crashes. These include:
- `ServerTrustManager` and associated certificate functionality is unavailable, so there is no certificate pinning and no client certificate support.
- Various methods of HTTP authentication may crash, including HTTP Basic and HTTP Digest. Crashes may occur if responses contain server challenges.
- Cache control through `CachedResponseHandler` and associated APIs is unavailable, as the underlying delegate methods aren't called.
- `URLSessionTaskMetrics` are never gathered.
Due to these issues, Alamofire is unsupported on Linux and Windows. Please report any crashes to the [Swift bug reporter](https://bugs.swift.org).
## Migration Guides
- [Alamofire 5.0 Migration Guide](https://github.com/Alamofire/Alamofire/blob/master/Documentation/Alamofire%205.0%20Migration%20Guide.md)
- [Alamofire 4.0 Migration Guide](https://github.com/Alamofire/Alamofire/blob/master/Documentation/Alamofire%204.0%20Migration%20Guide.md)
- [Alamofire 3.0 Migration Guide](https://github.com/Alamofire/Alamofire/blob/master/Documentation/Alamofire%203.0%20Migration%20Guide.md)
- [Alamofire 2.0 Migration Guide](https://github.com/Alamofire/Alamofire/blob/master/Documentation/Alamofire%202.0%20Migration%20Guide.md)
## Communication
- If you
Swift-局部支持旋转
需积分: 0 173 浏览量
更新于2023-08-29
收藏 518KB ZIP 举报
在Swift编程语言中,"局部支持旋转"通常指的是在iOS或macOS应用开发中处理界面在不同设备方向间旋转的能力。这种能力对于提供良好的用户体验至关重要,因为它允许用户根据自己的偏好或设备当前的方向来查看和交互应用程序。在iOS和macOS上,系统提供了自动旋转功能,但有时开发者可能需要对特定视图或控制器进行自定义旋转处理,这就是“局部支持旋转”的概念。
我们需要了解iOS和macOS中的设备方向。设备方向主要有四种:portrait(竖屏),landscape left(左横屏),landscape right(右横屏)以及portrait upside down(倒置竖屏)。系统会根据设备的物理传感器来检测这些方向,并通知应用进行相应的布局更新。
在Swift中,这个过程涉及到UIViewController的几个关键方法:
1. `shouldAutorotate()`:此方法返回一个布尔值,表示当前视图控制器是否应该自动旋转以响应设备方向的变化。默认情况下,它返回`true`,意味着视图控制器将自动旋转。
2. `supportedInterfaceOrientations()`:此方法返回一个UIInterfaceOrientationMask枚举的集合,表示视图控制器支持哪些界面方向。例如,如果只想支持竖屏,可以返回`.portrait`;若需同时支持竖屏和横屏,可返回`.allButUpsideDown`。
3. `preferredInterfaceOrientationForPresentation()`:此方法返回视图控制器在首次呈现时希望采用的界面方向。在某些情况下,你可能希望应用在启动时就固定在一个特定的方向。
4. `willTransition(to newInterfaceOrientation: UIInterfaceOrientation, with coordinator: UIViewControllerTransitionCoordinator)`:当界面即将旋转到新的方向时,系统会调用此方法。在这里,你可以进行任何与界面旋转相关的自定义布局调整。
5. `viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator)`:这是iOS特有的方法,用于在大小改变(比如旋转)时执行动画。`size`参数表示即将改变的新尺寸。
局部支持旋转的关键在于,不是所有的视图控制器都需要或者应该支持所有方向。例如,一个全屏播放视频的视图控制器可能只希望在横屏模式下工作。在这种情况下,你需要重写上述方法,以确保只有在你希望旋转的条件下才会发生旋转。
此外,如果你的应用是基于Storyboard构建的,你还可以在Interface Builder中设置每个ViewController的Interface Orientation属性,以控制它们在模拟器和设备上的显示方式。
Swift中的局部支持旋转涉及对UIViewController生命周期的理解以及对设备方向的恰当处理。通过精确控制这些方法,开发者可以创建出适应不同设备方向的灵活且用户体验优秀的应用。
冯汉栩
- 粉丝: 328
- 资源: 520
最新资源
- 【全年行事历】行政部全年活动计划表- A公司.xls
- 【全年行事历】活动复盘表.xlsx
- 【全年行事历】活动推广进度表.xlsx
- 【全年行事历】旅游团建行程安排表-XX山.xlsx
- 【全年行事历】旅行团建活动方案.pptx
- 【全年行事历】某公司团建活动方案-【户外烧烤】.doc.baiduyun.uploading.cfg
- 【全年行事历】企业文化年度活动计划表.xlsx
- 【全年行事历】年度员工关怀计划表.xlsx
- 【全年行事历】年度行政活动计划表.xlsx
- 【全年行事历】企业团队建设活动策划.pptx
- 【全年行事历】全年活动计划.xls
- 【全年行事历】团队建设企业文化行事历——工作计划.xlsx
- 【全年行事历】企业员工夏季团建活动策划一天.pptx
- 【全年行事历】团建费用分析.xlsx
- 【全年行事历】团建行程安排及出行清单.xlsx
- 【全年行事历】团建活动采购预算清单.xlsx