Post

Replies

Boosts

Views

Activity

How to always position button 2/3 way down the screen
I am making an application to work on many various iPhone models in portrait mode. I would like to have a button (with fixed height) always be afixed at a position 2/3 way down the screen display area no matter what iPhone model is used. I understand I can do this by pinning two views in the storyboard and then setting Equal heights with 1:3 and 2:3 ratios, however, is there a way to do this without introducing two views into the storyabord for this purpose?
2
0
895
Nov ’19
Setting constraint "isActive=false" causes fatal error
I have an imageView which has a top constraint IBOutlet called imageViewTopConstraint. In viewWillLayoutSubviews( ) I set the imageViewTopConstraint.constant value. The imageView displays properly for all iPhone models while in portrait mode, which is good.When I switch to landscape mode, I want to disable the imageViewTopConstraint, so the viewWillLayoutSubviews( ) has the following code:if UIDevice.current.orientation.isPortrait { imageViewTopConstraint.constant = (2 * screenHeight) / 3 imageViewTopConstraint.isActive = true } else if UIDevice.current.orientation.isLandscape { imageViewTopConstraint.isActive = false }IssueWhen I run the application it is initially in portrait mode. When I switch to landscape mode I receive the following fatal error at the line where I set "imageViewTopConstraint.isActive = false" to disable the constraint (line 6 above) Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional valueAny idea what is going on or what this means?
8
1
5.9k
Nov ’19
viewWillLayoutSubviews messing with my animation
I want to click a button and have my View slowly animate into the viewing area from the right side of the screen. Then click a second button and have the view animate off the screen from left to rightI added a Button (OpenButton with IBAction = openView) and a View (DataView) into my main ViewController. I set constraints on DataView to be the safe area for top(20), bottom(20), leading(16) and trailing(16). I also added a Button (CloseButton with IBAction = closeView) into the DataView.While in Portrait mode, clicking the OpenButton results in the OpenView( ) function being called and the DataView animating properly from right to left into the visible screen as desired. Clicking the CloseButton results in the view animating off the screen from left to right as desired. (Note: There are no calls to viewWillLayoutSubviews( ) which are made by the system at this time). I can click OpenButton and CloseButton multiple times and the animation works great each time while in Portrait mode.I now switched to Landscape mode. Clicking the OpenButton results in the openView( ) function being called and the DataView animating properly from right to left into the visible screen as desired. Clicking the CloseButton results in weird animation in the wrong places and the DataView does not properly go off the screen. Debugging has shown that when the CloseButton is pressed, then viewWillLayoutSubviews() and viewDidLayoutSubviews( ) are called, then the closeView( ) function is called and then viewWillLayoutSubviews() and viewDidLayoutSubviews( ) are called a second time. When viewDidLayoutSubviews() is called a second time, then the DataView snaps back to it's origin.x constraint value of 16 which results in it moving back to the leading safe area, which affects the animation which is currently going on. It seems like that is what is messes up the animation.Debug "print" statement output <Note: OPEN button clicked here>openScoreWindow -- enter dataView.frame.origin.x = 16.0 animation complete - openScoreWindow<Note: CLOSE button clicked here>viewWillLayoutSubviews dataView.frame.origin.x = 16.0viewDidLayoutSubviews dataView.frame.origin.x = 16.0closeScoreWindow -- enter dataView.frame.origin.x = 16.0viewWillLayoutSubviews dataView.frame.origin.x = 767.0 <--- this value is set in the UIVIew_Animate( ) in the closeView( ) function, as desiredviewDidLayoutSubviews dataView.frame.origin.x = 16.0 <--- this is proof the "leading" constraint is reset back to 16 during the active animation animation complete - closeScoreWindow . <-- this is when animation has completed** I tried to replicate this scenario by creating a separate brand new swift "test project" which just had the two buttons and dataView, however, in this "test project", the animation in portrait and landscape mode works as desired since viewWillLayoutSubviews() is never called when opening and closing the view. Oh well, for some reason, in my project, viewWillLayoutSubviews() is called twice when I click the Close button.I have no idea how to get around this issue. Any ideas?override func viewDidLoad() { super.viewDidLoad() dataView.isHidden = true print ("viewDidLayoutSubviews") print(" dataView.frame.origin.x = \(dataView.frame.origin.x)") print("") } @IBAction func openView() { print("openScoreWindow -- enter") print(" dataView.frame.origin.x = \(dataView.frame.origin.x)") //ensure view is positoned out of the viewing area dataView.frame.origin.x = getScreenSize().width + 100 //make view visible for eventual animation dataView.isHidden = false //animate view moving from right to left onto the screen UIView.animate(withDuration: 1.0, //1 second delay: 0, options: .curveEaseInOut, animations: { self.dataView.frame.origin.x = 16 }, completion: { [weak self] finished in print(" animation complete - openScoreWindow") print("") }) } } @IBAction func closeView() { print("closeScoreWindow -- enter") print(" dataView.frame.origin.x = \(dataView.frame.origin.x)") //animate view moving from left to right off the screen UIView.animate(withDuration: 3.0, //1 second delay: 0, options: .curveEaseInOut, animations: { //move view out of the viewing area self.dataView.frame.origin.x = self.getScreenSize().width + 100 }, completion: { [weak self] finished in //hide the view self?.dataView.isHidden = true print(" animation complete - closeScoreWindow") print("") }) }
18
0
5.4k
Nov ’19
How to ensure only one player sets game options in a match
I am able to authenticate the localplayer and find a match using the Game Center match viewcontroller. Assuming the match is going to have 4 players, I would like to ensure only 1 player sets the game options before they are matched with 3 other players. Of course, the 3 other players must know they should not set game options themselves. Any idea how this is done?
4
0
603
Dec ’19
Invite players programmatically into a match
I am using Swift 4.I am able to authenticate the localplayer and find a match using the Game Center match viewcontroller. I was also able to link the iOS simulator (player1) to my real iPhone 8 device (player2) into a match for test purposes.However, after the localplayer is authenticated, I would like to obtain a list of all my game center "friends" myself and then create my own viewController interface to invite/connect players into the game. I was able to call "GKLocalPlayer.local.loadChallengableFriends( )" to obtain the friends, but I am not sure how to properly invite them to a match one by one programmatically.Googling indicates GKMatchmaker inviteHandler, GKInvite and "player DidAccept" are involved but I do not know how to put this all together.Any pointers, hints or sample code would be greatly appreciated.In the meantime, I will continue to Google around
25
0
5.8k
Dec ’19
How can the application know it was started as a result of a Game Center Invite request?
When a user is not currently in the game application, I understand Game Center with push an Invite notification to the user's device asking them if they want to play the game. If they accept the invitation then Game Center will open the application automatically on the user's device. How can the game application know it was started as a result of an accepted invitation? If this can be determined then I can place the user into the game right away and bypass any option screens, displays menus, etc. which are no longer required.
11
1
1.2k
Dec ’19
Do Game Center peer-to-peer matches support more than 4 players now?
The Game Center Programming Guide clearly states real-time peer-to-peer matches supports 2 to 4 players only. However, I just notced I can call the findMatchWithMinPlayers method with the request.maxPlayers parameter set to a value of 5->16 and the GKMatchmakerViewController presents 5->16 players for me to invite.Is the Game Center Programming Guide out-of-date and real-time peer-to-peer matches support more than 4 players are now?I would like to know for sure so I can enable more than 4 player support into my game.
2
0
799
Dec ’19
How to send Invite to iPhone using IOS simulator
I am able to start a 2-player match between the IOS simluator and my connected iPhone. The IOS simulator starts hunting for a two player game using the GameKit Matchmaker View Controller and the iPhone requests a two-player match by entering my game application as well. Of course, the IOS simulator and my iPhone are using separate Game Center accounts to make this possible.I now want to test sending a true "Invite" request from the IOS simulator to the iPhone. When requesting a match in the IOS simulator, I can see my iPhone "user" is listed under the "Recently Played" section of the GameKit Matchmaker View Controller display window, after clicking the "Invite Player" button of course. When I select my iPhone "user" and then select "Play Now", my iPhone never receives an Invite request because the IOS simulator generates the following error:GKMatchmaker: invitePlayersWithRequest: - Error Inviting Players Error Domain=GKErrorDomain Code=3 "The requested operation could not be completed due to an error communicating with the server." UserInfo=GKServerStatusCode=5008, NSLocalizedDescription=The requested operation could not be completed due to an error communicating with the server., NSUnderlyingError=0x600002761c20 Error Domain=GKServerErrorDomain Code=5008 "status = 5008, missing required key: self-push-token" UserInfo={GKServerStatusCode=5008, NSLocalizedFailureReason=status = 5008, missing required key: self-push-tokenCan the IOS simulator be used to Invite iPhone users? If so, what does the error mean and how can I fix it?Does my iPhone have to be inside my game application to make this work ... I hope not.
6
0
1.2k
Dec ’19
How to assign constraints to a Scrollview which covers part of the screen only?
I want to use a Scrollview on the middle 2/3 of the screen so I did the following:1) I added a BaseView UIView to the middle 2/3 of my MainViewController and set the constraints to the following:leading =0trailing =0top to safe area = 150bottom to safe area = 1502) I added a MyScrollView inside the BaseView and set the constraints as follows:Note: All MyScrollview constraints remain RED after setting these constraints :>(leading = 0trailing = 0top = 0bottom = 03) I added a MyDataView UIView object inside the MyScrollView . The MyDataView starts at (0,0) and has a size of 500x500. I tried setting constraints on MyDataView to the following values but the top and leading constraints remain RED, most likely because the MyScrollView constraints are RED (see 2 above)top=0leading=0width=500height=5004) In the viewDidLoad function I added the following:ScrollView.delegate = selfScrollView.contentsize = MyDataView.frame.size5) I added various objects (buttons, labels, etc.) in the MyDataView UIView and tried to set constraints on these objects but the constraints are all RED as well. Questions:1) I am setting up the ScrollView properly so it can be used for 2/3 of the screen area only?2) How can I set valid constraints for the objects placed in the MyDataView and have them be a nice BLUE color?
20
0
14k
Dec ’19
loadChallengableFriends( ) error on iPhone 6 (iOS 12.4.4)
I am using the following method to obtain a list of GameCenter "friends" and it returns a list of player names on my iPhone 8 ( iOS 13.3 ) loadChallengableFriends(completionHandler: )When this method is called on an iPhone 6 ( iOS 12.4.4), I get the following error relating to the "loadChallengableFriends( )" method loadChallengableFriendsWithCompletionHandler:]: unrecognized selector sent to instance *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[GKLocalPlayerInternal loadChallengableFriendsWithCompletionHandler:]: unrecognized selector sent to instanceI was informed the iPhone 6 models no longer receive updates from Apple so this iPhone 6 is stuck at iOS 12.4.4 version.Since the loadChallengableFriends( ) method works on the iPhone 8 (iOS 13.3) and does not work on the iPhone 6 (iOS 12.4.4), I was thinking perhaps this method does not exist in iOS 12+The Apple documentation indicates the following for all of the "friends" methods I could find:a) loadChallengableFriends( ) SDK iOS 13+b) loadFriendPlayers( ) SDK iOS 8.0 - 10.0 (deprecated)c) loadFriends( ) SDK iOS 4.1- 8.0. (deprecated)Questions1) Do I interpret the "SDK iOS 13+" statement to mean the loadChallengableFriends( ) method does not exist before iOS 13?2) What method do we use to find "friends" between "iOS 10 and iOS 13" then ? Perhaps this is not supported durine that time?
0
0
382
Jan ’20
What is a responsible time to connect to a Game Center match?
Based on the game options within my game, which are selected by the player, there can be multiple types of matches the player could join which have the required "number of players" but also share the same "player group number". I am calling "findMatch()" for each different match type one by one, however, I would like to know what a reasonable time would be to wait for Game Center to determine if there is an actual match in which the player can join. When there is not a match available for the game type I am currently searching for, then I cancel the match request and move on to search for the next type of match, via a new findMatch() call and so on.Would waiting 10 seconds for Game Center to determine if a match exists be reasonable before starting a new "findMatch( )" request in Game Center?
4
0
603
Jan ’20
It seems like Game Center is sending same data twice
Is it possible for Game Center to send the exact same data to the same player twice?I am frequently (not all of the time) noticing, the same exact data being received twice, which is causing issues in my application.I am using the following functions in GameKitHelper to send and receive data in my application:func sendDataToPlayer(data: Data!, gkPlayer: GKPlayer) { var playerArray: [GKPlayer] = [ ] playerArray.append(gkPlayer) do { try myMatch?.send(data, to: playerArray, dataMode: .reliable) } catch { } } func match(_ match: GKMatch, didReceive data: Data, forRecipient recipient: GKPlayer, fromRemotePlayer player: GKPlayer)I am experiencing the same exact data coming into the "didReceive data:" function with the exact same data, recipient and player valuesHas anyone seen this duplicate data issue before?I see this issue when testing with 2 real iPhones and the simulator (ie: 3 players). I do not see this issue when testing with 1 iPhone and the simualtor (ie: 2 players).As a side question .... what is the difference between:1) match(_: didReceive: forRecipient: fromRemotePlayer:) and2) match (_: didReceive: fromRemotePlayer:)
1
0
511
Feb ’20
iPhone with lower iOS version cannot be added as a friend to Game Center
My son has an iPhone 6 which is stuck at iOS 12.4.4 since it is no longer supported I guess. My iPhone is at iOS 13.3.1. When I go into my Settings/Game Center and try to add him as a friend, he receives a IM message asking if he will be my friend. When he clicks on it, a display pops up indicating he must upgrade to iOS 13.3 to accept the friend invite.1) Is there anyway around this so I can add my son as a "Friend" in Game Center?2) Most importantly, will I be able to "Invite" my son into a match using the GameCenterMatchMaker view controller when my game is completed? If it matters, the "Deployment Info" for my game in XCode indicates a "Target = iOS 12.4" . I assume this means my game will be allowed to be downloaded by any iPhone having iOS 12.4 or greater ?
0
0
430
Feb ’20