小编JD.*_*JD.的帖子

"通过网络连接"无线调试无法正常工作Xcode 9

我想通过网络运行我的iOS应用程序.但它没有像我预期的那样工作.网络标志未显示.

在此输入图像描述

我在用:

macOS Sierra - 10.12.6(在Mac mini中)

Xcode - 9.0(9A235)

iOS - 11.0

注意:Mac mini和iPhone都连接到同一网络.

已经尝试过:

  1. 改变另一个网络

  2. 重启iPhone和Mac mini两次.

  3. 取消配对设备并再次配对设备.

我错过了什么吗?

xcode ios ios11 xcode9

19
推荐指数
2
解决办法
7669
查看次数

为什么在 SwiftUI 中的 TabView 中切换选项卡时,在 onDisappear 之后再次调用 onAppear?

如果有任何更改,我会在出现选项卡项时调用 API。为什么在调用 onDisappear 之后调用 onAppear?

这是一个简单的例子:

struct ContentView: View {
    var body: some View {
        TabView {
            NavigationView {
                Text("Home")
                    .navigationTitle("Home")
                    .onAppear {
                        print("Home appeared")
                    }
                    .onDisappear {
                        print("Home disappeared")
                    }
            }
            .tabItem {
                Image(systemName: "house")
                Text("Home")
            }.tag(0)
        
            NavigationView {
                Text("Account")
                    .navigationTitle("Account")
                    .onAppear {
                        print("Account appeared")
                    }
                    .onDisappear {
                        print("Account disappeared")
                    }
            }
            .tabItem {
                Image(systemName: "gear")
                Text("Account")
            }.tag(1)
        }
    }
}    
Run Code Online (Sandbox Code Playgroud)

只需运行上面的代码,我们将在 onDisappear 之后看到 onAppear。

Home appeared
---After switch tab to Account---
Home disappeared
Account appeared
Home appeared
Run Code Online (Sandbox Code Playgroud)

有没有办法避免这种情况?

ios tabview swiftui

13
推荐指数
2
解决办法
1335
查看次数

图像建议不起作用Xcode 10

我正在尝试将图像设置为UIImageView.它在旧版本中运行良好.

在Xcode 9.4.1中

在此输入图像描述

但是在Xcode 10中

在此输入图像描述

当我尝试键入图像名称时,图像建议未显示.

甚至"Image Literal"也无效.双击上面的图标也无法正常工作.

Xcode首选项中是否有任何设置?

如何像以前一样启用图像建议?

uiimageview uiimage ios xcode10

12
推荐指数
2
解决办法
4581
查看次数

当应用程序处于前台时获取本地通知 Swift 4 iOS 11

我想在我的应用程序处于前台时收到本地通知,当我尝试使用以下代码时,它永远不会触发通知,但是当我在后台输入应用程序时,它确实触发了。

这是我尝试过的:

//Schedule a Local Notification
func ScheduleNotification(timeInterval: Double, repeats: Bool, notificationBody:String, title:String){

    let trigger = UNTimeIntervalNotificationTrigger.init(timeInterval: timeInterval, repeats: repeats)

    let center = UNUserNotificationCenter.current()

    let identifier = "UYLLocalNotification"
    let content = UNMutableNotificationContent()
    content.title = title
    content.body = notificationBody
    content.sound = UNNotificationSound.default()
    let request = UNNotificationRequest(identifier: identifier, content: content, trigger: trigger)
    center.add(request, withCompletionHandler: { (error) in
        if let error = error {
            //Something went wrong
            print(error.localizedDescription)
        }
    })
}

override func viewDidLoad() {
    super.viewDidLoad()

    if Currentcount < data.count {
        self.ScheduleNotification(timeInterval: 5.0, …
Run Code Online (Sandbox Code Playgroud)

ios uilocalnotification swift

5
推荐指数
1
解决办法
6498
查看次数

UICollectionView(在水平CollectionView内部)滚动时如何缩小大标题?

我正在使用 Brian 的 (LBTA) youtube 演示来创建可滚动的水平菜单栏。

我正在使用collectionView.contentInsetAdjustmentBehavior = .never以避免在调试区域中出现警告。

我只想添加Large titleiOS 11 中引入的内容。

设置navigationController?.navigationBar.prefersLargeTitles = true为启用大标题。它按预期运行良好。

现在,我想在滚动 UIcollectionView(在水平 UICollectionView 内)时将大标题缩小为普通标题。

如何将 scrollView(在 UICollectionView 的滚动中)连接到 NavigationController/NavigationItem 以缩小?

在此处输入图片说明

ios uicollectionview swift ios11 preferslargetitles

5
推荐指数
0
解决办法
395
查看次数

CollectionView多个单元格选择

我有一个集合视图,有两个自定义单元格,一个用于网格,一个用于列表,我希望能够触摸单元格并选择它们,如果要删除或共享它们,我现在想要的只能选择和deselct他们,生病我的代码下面的结果是当我触摸一个单元格所有单元格被选中!这是代码:

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    if isGridSelected {

        let cell:cell2_Class = collectionView.dequeueReusableCellWithReuseIdentifier("cell2", forIndexPath: indexPath) as! cell2_Class

        cell.listImage.image = imageArray[indexPath.row]

        if flag == true {
            cell.layer.borderColor = UIColor.blueColor().CGColor
            cell.layer.borderWidth = 3
            cancelButton.hidden = false
        } else {
            cell.layer.borderColor = UIColor.clearColor().CGColor
            cancelButton.hidden = true
        }
        return cell
    } else {
        let cell:PhotoCollectionCell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! PhotoCollectionCell

        if flag == true {
            cell.layer.borderColor = UIColor.blueColor().CGColor
            cell.layer.borderWidth = 3
            cancelButton.hidden = false
        } else {
            cell.layer.borderColor = …
Run Code Online (Sandbox Code Playgroud)

arrays ios uicollectionview swift

4
推荐指数
1
解决办法
9103
查看次数

UITabBar边界和阴影问题

我需要将阴影效果放入UITabBar,我通过以下代码得到:

tabBar.layer.shadowOffset = CGSize(width: 0, height: 0)
tabBar.layer.shadowRadius = 4.0
tabBar.layer.shadowColor = UIColor.gray.cgColor
tabBar.layer.shadowOpacity = 0.6
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

它运作得很好.

但是,我需要删除顶部的边框UITabBar,并通过搜索我得到self.tabBar.clipsToBounds = true,通过放置代码,它删除边框,但它也删除阴影效果.

在此输入图像描述

我需要像下面的图片:

在此输入图像描述

没有边框,但有阴影效果.

任何帮助将不胜感激.

uitabbar ios swift

4
推荐指数
2
解决办法
1297
查看次数

在Swift中更改标签栏徽章大小

如何更改标签栏徽章大小?

我将标签栏徽章值设置为位置

tabBarController?.tabBar.items?[4].badgeValue = "1"
Run Code Online (Sandbox Code Playgroud)

但我无法更改红色圆圈标签栏的徽章大小.

谢谢!

uitabbarcontroller uitabbaritem ios swift

3
推荐指数
1
解决办法
3018
查看次数

如何检测滑动和拖动之间的手势?

我想在主视图中创建一个视图,并将滑动和拖动(平移)手势应用于该视图.但是如何知道那是刷卡还是平移手势?

uigesturerecognizer uiswipegesturerecognizer uipangesturerecognizer swift

2
推荐指数
1
解决办法
2066
查看次数

UISearchBar iOS 10+中的UITextField backgroundColor

我正在尝试将搜索栏中文本字段的背景颜色设置为自定义颜色。我看着这里的答案无济于事:

无法更改搜索栏背景颜色

看到搜索栏的文本字段为红色吗?我遵循了代码,甚至可以验证是否找到了UISearchBarTextField对象,并且它的背景色被设置为UIColor.red,但是颜色没有改变。

我把超级视图的所有背景颜色弄乱了,希望对它有帮助,但我无法改变这种颜色。也许有一些新技巧,或者有人可以阐明某些可能以某种方式覆盖颜色的东西。

extension UISearchBar {
    var textField: UITextField? {
        return subviews.first?.subviews.first(where: { $0.isKind(of: UITextField.self) }) as? UITextField
    }
}

searchBar.textField?.backgroundColor = UIColor.red // <-- Not working
let textFieldInsideUISearchBarLabel = searchBar.textField?.value(forKey: "placeholderLabel") as? UILabel
textFieldInsideUISearchBarLabel?.textColor = UIColor.lightGray
Run Code Online (Sandbox Code Playgroud)

请注意,UITextField对象内的文本正像我想要的那样变为lightGray,而不是UITextField背景色。

uitextfield uisearchbar uibackgroundcolor ios10 ios11

2
推荐指数
1
解决办法
1156
查看次数