archive-com.com » COM » T » TECHOTOPIA.COM

Total: 1018

Choose link from "Titles, links and description words view":

Or switch to "Titles and links view".
  • An Overview of iOS 7 Multitouch, Taps and Gestures - Techotopia
    chain If the first responder is not able to handle the event it will also pass it to the next responder in the chain and so on until it either reaches a responder that handles the event or it reaches the end of the chain the UIApplication object where it will either be handled or discarded Take for example a UIView with a UIButton subview If the user touches the screen over the button then the button as first responder will receive the event If the button is unable to handle the event it will need to be passed up to the view object If the view is also unable to handle the event it would then be passed to the view controller and so on When working with the responder chain it is important to note that the passing of an event from one responder to the next responder in the chain does not happen automatically If an event needs to be passed to the next responder code must be written to make it happen Forwarding an Event to the Next Responder An event may be passed on to the next responder in the response chain by calling the nextResponder method of the current responder passing through the method that was triggered by the event and the event itself Take for example a situation where the current responder object is unable to handle a touchesBegan event In order to pass this to the next responder the touchesBegan method of the current responder will need to make a call as follows void touchesBegan NSSet touches withEvent UIEvent event self nextResponder touchesBegan touches withEvent event eBookFrenzy com Purchase the fully updated iOS 9 Swift 2 Xcode 7 edition of this book in eBook 12 99 or Print 39 99 format iOS 9 App Development Essentials Print and eBook ePub PDF Kindle edition contains 105 chapters Gestures Gesture is an umbrella term used to encapsulate any single interaction between the touch screen and the user starting at the point that the screen is touched by one or more fingers and the time that the last finger leaves the surface of the screen Swipes pinches stretches and flicks are all forms of gesture Taps A tap as the name suggests occurs when the user touches the screen with a single finger and then immediately lifts it from the screen Taps can be single taps or multiple taps and the event will contain information about the number of times a user tapped on the screen Touches A touch occurs when a finger establishes contact with the screen When more than one finger touches the screen each finger registers as a touch up to a maximum of five fingers Touch Notification Methods Touch screen events cause one of four methods on the first responder object to be called The method that gets called for a specific event will depend on the nature of the interaction In order to handle events therefore it is important to

    Original URL path: http://www.techotopia.com/index.php/An_Overview_of_iOS_7_Multitouch,_Taps_and_Gestures (2016-02-13)
    Open archived version from archive


  • An Example iOS 7 Touch, Multitouch and Tap Application - Techotopia
    be sure to stretch them so that they reach to the right hand margin of the view area Figure 44 1 Select label to the right of the Method label display the Assistant Editor panel and verify that the editor is displaying the contents of the TouchViewController h file Ctrl click on the same label object and drag to a position just below the interface line in the Assistant Editor Release the line and in the resulting connection dialog establish an outlet connection named methodStatus Repeat the above steps to establish outlet connections for the remaining labels object to properties named touchStatus and tapStatus Enabling Multitouch on the View By default views are configured to respond to only single touches in other words a single finger touching or tapping the screen at any one time For the purposes of this example we plan to detect multiple touches In order to enable this support it is necessary to change an attribute of the view object To achieve this click on the background of the View window display the Attributes Inspector View Utilities Show Attributes Inspector and make sure that the Multiple Touch option is selected in the Interaction section at the bottom of the window Figure 44 2 eBookFrenzy com Purchase the fully updated iOS 9 Swift 2 Xcode 7 edition of this book in eBook 12 99 or Print 39 99 format iOS 9 App Development Essentials Print and eBook ePub PDF Kindle edition contains 105 chapters Implementing the touchesBegan Method When the user touches the screen the touchesBegan method of the first responder is called In order to capture these event types we need to implement this method in our view controller In the Xcode project navigator select the TouchViewController m file and add the touchesBegan method as follows void touchesBegan NSSet touches withEvent UIEvent event NSUInteger touchCount touches count NSUInteger tapCount touches anyObject tapCount methodStatus text touchesBegan touchStatus text NSString stringWithFormat d touches touchCount tapStatus text NSString stringWithFormat d taps tapCount This method obtains a count of the number of touch objects contained in the touches set essentially the number of fingers touching the screen and assigns it to a variable It then gets the tap count from one of the touch objects The code then updates the methodStatus label to indicate that the touchesBegan method has been triggered constructs a string indicating the number of touches and taps detected and displays the information on the touchStatus and tapStatus labels accordingly Implementing the touchesMoved Method When the user moves one or more fingers currently in contact with the surface of the touch screen the touchesMoved method is called repeatedly until the movement ceases In order to capture these events it is necessary to implement the touchesMoved method in our view controller class void touchesMoved NSSet touches withEvent UIEvent event NSUInteger touchCount touches count NSUInteger tapCount touches anyObject tapCount methodStatus text touchesMoved touchStatus text NSString stringWithFormat d touches touchCount tapStatus text NSString stringWithFormat d taps tapCount Once again we

    Original URL path: http://www.techotopia.com/index.php/An_Example_iOS_7_Touch,_Multitouch_and_Tap_Application (2016-02-13)
    Open archived version from archive

  • Detecting iOS 7 Touch Screen Gesture Motions - Techotopia
    Interface The application will display the X and Y coordinates of the touch and update these values in real time as the finger moves across the screen When the finger is lifted from the screen the start and end coordinates of the gesture will then be displayed on two label objects in the user interface Select the Main storyboard file and using Interface Builder create a user interface such that it resembles the layout in Figure 45 1 Figure 45 1 Be sure to stretch the labels so that they both extend to cover most of the width of the view eBookFrenzy com Purchase the fully updated iOS 9 Swift 2 Xcode 7 edition of this book in eBook 12 99 or Print 39 99 format iOS 9 App Development Essentials Print and eBook ePub PDF Kindle edition contains 105 chapters Select the top label object in the view canvas display the Assistant Editor panel and verify that the editor is displaying the contents of the TouchMotionViewController h file Ctrl click on the same label object and drag to a position just below the interface line in the Assistant Editor Release the line and in the resulting connection dialog establish an outlet connection named xCoord Repeat this step to establish an outlet connection to the second label object named yCoord Next select the TouchMotionViewController h file verify that the outlets are correct then declare a property in which to store coordinates of the start location on the screen import UIKit UIKit h interface TouchMotionViewController UIViewController property strong nonatomic IBOutlet UILabel xCoord property strong nonatomic IBOutlet UILabel yCoord property CGPoint startPoint end Implementing the touchesBegan Method When the user first touches the screen the location coordinates need to be saved in the startPoint instance variable and those coordinates reported to the user This can be achieved by implementing the touchesBegan method in the TouchMotionViewController m file as follows void touchesBegan NSSet touches withEvent UIEvent event UITouch theTouch touches anyObject startPoint theTouch locationInView self view CGFloat x startPoint x CGFloat y startPoint y xCoord text NSString stringWithFormat x f x yCoord text NSString stringWithFormat y f y Implementing the touchesMoved Method When the user s finger moves across the screen the touchesMoved event will be called repeatedly until the motion stops By implementing the touchesMoved method in our view controller therefore we can detect the motion and display the revised coordinates to the user void touchesMoved NSSet touches withEvent UIEvent event UITouch theTouch touches anyObject CGPoint touchLocation theTouch locationInView self view CGFloat x touchLocation x CGFloat y touchLocation y xCoord text NSString stringWithFormat x f x yCoord text NSString stringWithFormat y f y Implementing the touchesEnded Method When the user s finger lifts from the screen the touchesEnded method of the first responder is called The final task therefore is to implement this method in our view controller such that it displays the start and end points of the gesture void touchesEnded NSSet touches withEvent UIEvent event UITouch theTouch touches anyObject CGPoint

    Original URL path: http://www.techotopia.com/index.php/Detecting_iOS_7_Touch_Screen_Gesture_Motions (2016-02-13)
    Open archived version from archive

  • Identifying Gestures using iOS 7 Gesture Recognizers - Techotopia
    Used to identify when the user touches the screen with one or more fingers for a specified period of time also referred to as touch and hold These gesture recognizers must be attached to the view on which the gesture will be performed via a call to the view object s addGestureRecognizer method Recognizers must also be assigned an action method that is to be called when the specified gesture is detected Gesture recognizers may subsequently be removed from a view via a call to the view s removeGestureRecognizer method passing through as an argument the recognizer to be removed Recognizer Action Messages The iOS 7 gesture recognizers use the target action model to notify the application of the detection of a specific gesture When an instance of a gesture recognizer is created it is provided with the reference to the method to be called in the event that the corresponding gesture is detected Discrete and Continuous Gestures Gestures fall into two distinct categories discrete and continuous A discrete gesture results in only a single call being made to the corresponding action method Tap gestures including multiple taps are considered to be discrete because they only trigger the action method once Gestures such as swipes pans rotations and pinches are deemed to be continuous in that they trigger a constant stream of calls to the corresponding action methods until the gesture ends Obtaining Data from a Gesture Each gesture action method is passed as an argument a UIGestureRecognizer sender object which may be used to extract information about the gesture For example information about the scale factor and speed of a pinch gesture may be obtained by the action method Similarly the action method assigned to a rotation gesture recognizer may ascertain the amount of rotation performed by the user and the corresponding velocity Recognizing Tap Gestures Tap gestures are detected using the UITapGestureRecognizer class This must be allocated and initialized with an action selector referencing the method to be called when the gesture is detected The number of taps that must be performed to constitute the full gesture may be defined by setting the numberOfTapsRequired property of the recognizer instance The following code for example will result in a call to the tapsDetected method when two consecutive taps are detected on the corresponding view UITapGestureRecognizer doubleTap UITapGestureRecognizer alloc initWithTarget self action selector tapDetected doubleTap numberOfTapsRequired 2 self view addGestureRecognizer doubleTap A template method for the action method for this and other gesture recognizers is as follows IBAction tapDetected UIGestureRecognizer sender Code to respond to gesture here Recognizing Pinch Gestures Pinch gestures are detected using the UIPinchGestureRecognizer class For example UIPinchGestureRecognizer pinchRecognizer UIPinchGestureRecognizer alloc initWithTarget self action selector pinchDetected self view addGestureRecognizer pinchRecognizer eBookFrenzy com Purchase the fully updated iOS 9 Swift 2 Xcode 7 edition of this book in eBook 12 99 or Print 39 99 format iOS 9 App Development Essentials Print and eBook ePub PDF Kindle edition contains 105 chapters Detecting Rotation Gestures Rotation gestures are recognized

    Original URL path: http://www.techotopia.com/index.php/Identifying_Gestures_using_iOS_7_Gesture_Recognizers (2016-02-13)
    Open archived version from archive

  • An iOS 7 Gesture Recognition Tutorial - Techotopia
    outer edges of the view until the blue dotted lines representing the recommended margins appear and then modify the label properties to center the label text Select the label object in the view canvas display the Assistant Editor panel and verify that the editor is displaying the contents of the RecognizerViewController h file Ctrl click on the same label object and drag to a position just below the interface line in the Assistant Editor Release the line and in the resulting connection dialog establish an outlet connection named statusLabel Next the non visual gesture recognizer objects need to be added to the design Scroll down the list of objects in the Object Library panel until the Tap Gesture Recognizer object comes into view Drag and drop the object onto the View in the design area if the object is dropped outside the view the connection between the recognizer and the view on which the gestures are going to be performed will not be established Repeat these steps to add Pinch Rotation Swipe and Long Press Gesture Recognizer objects to the design Note that document outline panel which can be displayed by clicking on the arrow button in the lower left hand corner of the storyboard panel has updated to reflect the presence of the gesture recognizer objects as illustrated in Figure 47 1 Figure 47 1 Within the document outline panel select the Tap Gesture Recognizer instance and display the Attributes Inspector View Utilities Show Attributes Inspector Within the attributes panel change the Taps value to 2 so that only double taps are detected Similarly select the Long Press Recognizer object and change the Press Duration attribute to 3 seconds Having added and configured the gesture recognizers the next step is to connect each recognizer to its corresponding action method eBookFrenzy com Purchase the fully updated iOS 9 Swift 2 Xcode 7 edition of this book in eBook 12 99 or Print 39 99 format iOS 9 App Development Essentials Print and eBook ePub PDF Kindle edition contains 105 chapters Display the Assistant Editor and verify that it is displaying the content of RecognizerViewController h Ctrl click on the Tap Gesture Recognizer object in the document outline panel and drag the line to the area immediately beneath the newly created outlet in the Assistant Editor panel Release the line and within the resulting connection dialog establish an Action method configured to call a method named tapDetected with the id value set to UITapGestureRecognizer as illustrated in Figure 47 2 Figure 47 2 Repeat these steps to establish action connections for the pinch rotation swipe and long press gesture recognizers to methods named pinchDetected rotationDetected swipeDetected and longPressDetected respectively taking care to select the corresponding id value for each action On completion of the above steps the RecognizerViewController h file should read as follows import UIKit UIKit h interface RecognizerViewController UIViewController property strong nonatomic IBOutlet UILabel statusLabel IBAction tapDetected UITapGestureRecognizer sender IBAction rotationDetected UIRotationGestureRecognizer sender IBAction pinchDetected UIPinchGestureRecognizer sender IBAction swipeDetected

    Original URL path: http://www.techotopia.com/index.php/An_iOS_7_Gesture_Recognition_Tutorial (2016-02-13)
    Open archived version from archive

  • An Overview of iOS 7 Collection View and Flow Layout - Techotopia
    the collection view is controlled by the layout object assigned to the collection view Instances of UICollectionViewCell class are not typically instantiated directly in code Instead the class is registered as the cell class for a collection view and is then created internally as needed Collection views are scrollable and consequently at any one time only a subset of the cells in a collection are visible This enables the system to reuse cell objects that are currently scrolled outside of the viewable area of the screen and only create new ones when necessary This is achieved using a queuing mechanism and results in improved performance particularly when dealing with larger data sets The UICollectionReusableView Class The base class from which the UICellCollectionView class is derived this class is most typically subclassed in application code to create supplementary views The UICollectionViewFlowLayout Class The UICollectionViewFlowLayout class is the default layout class for collection views and is designed to layout cells in a grid like manner This class requires a delegate object that conforms to the UICollectionViewDelegateFlowLayout protocol which is typically the collection view s UICollectionViewDelegate object By default flow is implemented in a manner similar to that of line wrapping in a text editor When one row of cells is full the cells flow onto the next row and so on until all cells capable of fitting into the currently visible display region are visible The flow layout class supports both horizontal and vertical scrolling configurable via the scrollDirection property In addition properties such as the spacing between lines of cells in the grid and cells in a row may be configured together with default sizes for cells and supplementary views unless overridden via methods implemented in the delegate object The UICollectionViewLayoutAttributes Class Each item in a collection view be it a cell or a supplementary view has associated with it a set of attributes The UICollectionViewLayoutAttributes class serves as an object into which these attributes can be stored and transferred between objects A Flow Layout object will for example be asked by the collection view object to return the attributes for a cell at a given index in a collection view via a call to the layoutAttributesForItemAtIndexPath method This method in turn returns those attributes encapsulated in a UICollectionViewLayoutAttributes object Similarly such object instances can be used to apply new attributes to a collection view element The attributes stored by the UICollectionViewLayoutAttributes class are as follows keeping in mind that this class may be subclassed and extended to allow the storage of other values alpha the transparency of the item center the location of the center of the item frame the CGRect frame in which the item is displayed hidden whether or not the item is currently visible indexPath the index path location of the item in the collection view representedElementCategory The type of item for which the attributes apply i e for a cell supplementary or decoration view size the size of the item transform3D the current transform of the item This attribute can be used to perform tasks such as rotating or scaling the item zIndex controls the position of the item in the z axis in other words whether or not it is on top of or below other overlapping items eBookFrenzy com Purchase the fully updated iOS 9 Swift 2 Xcode 7 edition of this book in eBook 12 99 or Print 39 99 format iOS 9 App Development Essentials Print and eBook ePub PDF Kindle edition contains 105 chapters The UICollectionViewDataSource Protocol The UICollectionViewDataSource protocol needs to be implemented by the class responsible for supplying the collection view with the pre configured cells and supplementary views to be displayed to the user This basically consists of a number of methods that define information such as how many items of data are to be displayed how the data is divided into different sections and most importantly supplies the collection view with the cell objects to be displayed Mandatory methods in the protocol are as follows collectionView numberOfItemsInSection Returns the number of items to be displayed in the specified section of the collection view collectionView cellForItemAtIndexPath This method is called by the collection view when it is ready to display a cell at the specified index path location in the collection view It is required to return a cell object configured appropriately for the referenced index Optional methods in the protocol are as follows numberOfSectionsInCollectionView Indicates to the collection view the number of sections into which the collection view is to be divided collectionView viewForSupplementaryElementOfKind atIndexPath Called by the collection view to request a supplementary view of the specified kind Returns an appropriately configured object to be displayed In terms of the UICollectionViewFlowLayout class the layout will request a supplementary view for either a header UICollectionElementKindSectionHeader or footer UICollectionElementKindSectionFooter The UICollectionViewDelegate Protocol The UICollectionViewDelegate protocol defines a set of optional methods which if implemented will be called when certain events take place within the corresponding collection These methods relate primarily to handling user interaction with the collection view elements such as selecting a specific cell Some of the key methods in this protocol include collectionView shouldSelectItemAtIndexPath Returns a boolean value indicating whether the specified item is selectable by the user collectionView didSelectItemAtIndexPath Called by the collection view when the specified item has been selected by the user collectionView shouldDeselectItemAtIndexPath Returns a boolean value to indicate whether the specified item may be deselected by the user collectionView didDeselectItemAtIndexPath Called by the collection view when the specified item has been selected by the user collectionView shouldHighlightItemAtIndexPath Returns a boolean value indicating whether the specified item should be highlighted as a pre cursor to possible selection by the user collectionView didHighlightItemAtIndexPath Called by the collection view when the specified item has been highlighted collectionView didUnhighlightItemAtIndexPath Called by the collection view when the specified item has been un highlighted collectionView didEndDisplayingCell forItemAtIndexPath Called by the collection view when the specified cell has been removed from the collection view collectionView didEndDisplayingSupplementaryView forElementOfKind atIndexPath

    Original URL path: http://www.techotopia.com/index.php/An_Overview_of_iOS_7_Collection_View_and_Flow_Layout (2016-02-13)
    Open archived version from archive

  • An iOS 7 Storyboard-based Collection View Tutorial - Techotopia
    following URL http www ebookfrenzy com web ios7 Once downloaded unzip the archive and drag and drop the 12 image files onto the Supporting Files section of the Xcode project navigator panel Next select the MyCollectionViewController h file and declare an array into which will be stored the image file names import UIKit UIKit h interface MyCollectionViewController UICollectionViewController property strong nonatomic NSMutableArray carImages end Finally edit the MyCollectionViewController m file and modify the viewDidLoad method to initialize the array with the names of the car image files void viewDidLoad super viewDidLoad carImages chevy small jpg mini small jpg rover small jpg smart small jpg highlander small jpg venza small jpg volvo small jpg vw small jpg ford small jpg nissan small jpg honda small jpg jeep small jpg mutableCopy Note that we are using Modern Objective C syntax to initialize the array This approach returns a non mutable array by default Later in the chapter we will be implementing code to remove items from the array so we need to call the mutableCopy method of the array to make sure we can modify the array later Implementing the Data Source As outlined in the chapter entitled An Overview of iOS 7 Collection View and Flow Layout a collection view needs a data source and a delegate in order to provide all the functionality it is capable of providing By default Xcode has designated the MyCollectionViewController class as both the delegate and data source for the UICollectionView in the user interface To verify this select the black background of the collection view controller in the storyboard to select the UICollectionView subclass instance and display the Connections Inspector select the far right item at the top of the Utilities panel or use the View Utilities Show Connection Inspector menu option Assuming that the connections have been made the Outlets section of the panel will be configured as shown in Figure 49 6 Figure 49 6 The next step is to declare which protocols the MyCollectionViewController class is going to implement Since the class will also need to work with the MyCollectionViewCell class now is also a good opportunity to import the header file for this class Select the MyCollectionViewController h file and modify it so that it reads as outlined in the following listing import UIKit UIKit h import MyCollectionViewCell h interface MyCollectionViewController UICollectionViewController UICollectionViewDataSource UICollectionViewDelegate property strong nonatomic NSMutableArray carImages end A number of data source methods will now be implemented to conform with the UICollectionViewDataSource protocol The first lets the collection view know how many sections are to be displayed For the purposes of this example there is only going to be one section so select the MyCollectionViewController m file and implement the numberOfSectionsInCollectionView method to return a value of 1 pragma mark pragma mark UICollectionViewDataSource NSInteger numberOfSectionsInCollectionView UICollectionView collectionView return 1 The next method is called by the collection view to identify the number of items that are to be displayed in each section In this case the sole collection view section will be required to display a cell for each element in the carImages array NSInteger collectionView UICollectionView collectionView numberOfItemsInSection NSInteger section return carImages count The cellForItemAtIndexPath method will be called by the collection view in order to obtain cells configured based on the indexPath value passed to the method This method will request a cell object from the reuse queue and then set the image on the Image View object which was configured in the cell prototype earlier in this chapter using the index path row as the index into the carImages array UICollectionViewCell collectionView UICollectionView collectionView cellForItemAtIndexPath NSIndexPath indexPath MyCollectionViewCell myCell collectionView dequeueReusableCellWithReuseIdentifier MyCell forIndexPath indexPath UIImage image long row indexPath row image UIImage imageNamed carImages row myCell imageView image image return myCell Testing the Application Compile and run the application either on a physical iPhone device or using the iOS Simulator Once loaded the collection view will appear as illustrated in Figure 49 7 Clearly each cell has been displayed at a fixed size causing the images to be compressed to fit into the containing cell In order to improve the visual experience some work is clearly still needed Figure 49 7 eBookFrenzy com Purchase the fully updated iOS 9 Swift 2 Xcode 7 edition of this book in eBook 12 99 or Print 39 99 format iOS 9 App Development Essentials Print and eBook ePub PDF Kindle edition contains 105 chapters Setting Sizes for Cell Items When the prototype cell was designed it was set to a specific size Unless additional steps are taken each cell within the collection view will appear at that size This means that images are not displayed at their original size In actual fact all of the car images differ in size from each other What is needed is a way to set the size of each cell based on the size of the content it is required to display in this instance the dimensions of the corresponding image As outlined in the previous chapter if a method named sizeForItemAtIndexPath is implemented in the UICollectionViewFlowLayoutDelegate protocol class which by default is the same class as the UICollectionViewDelegate delegate it will be called for each cell to request size information Clearly by implementing this method it will be possible to have each image displayed at its own size Remaining in MyCollectionViewController m implement this method to identify the size of the current image and return the result to the collection view pragma mark pragma mark UICollectionViewFlowLayoutDelegate CGSize collectionView UICollectionView collectionView layout UICollectionViewLayout collectionViewLayout sizeForItemAtIndexPath NSIndexPath indexPath UIImage image long row indexPath row image UIImage imageNamed carImages row return image size Run the application once again and note that as shown in Figure 49 8 the images are now displayed at their original sizes Figure 49 8 Changing Scroll Direction As currently configured the flow layout object assigned to the collection view is in vertical scrolling mode As a demonstration of both one of the delegate methods for handling user interaction

    Original URL path: http://www.techotopia.com/index.php/An_iOS_7_Storyboard-based_Collection_View_Tutorial (2016-02-13)
    Open archived version from archive

  • Subclassing and Extending the iOS 7 Collection View Flow Layout - Techotopia
    calls a custom method named modifyLayoutAttributes and then returns the modified attributes to the collection view It will be the task of the modifyLayoutAttributes method which will be implemented later to apply the resize and movement effects to the attributes of the cell over which the pinch gesture is taking place Implementing the layoutAttributesForElementsInRect Method The layoutAttributesForElementsInRect method will need to perform a similar task to the previous method in terms of getting the attributes values for cells in the designated display region from the superclass calling the modifyLayoutAttributes method and returning the results to the collection view object NSArray layoutAttributesForElementsInRect CGRect rect Get all the attributes for the elements in the specified frame NSArray allAttributesInRect super layoutAttributesForElementsInRect rect for UICollectionViewLayoutAttributes cellAttributes in allAttributesInRect Modify the attributes for the cells in the frame rect self modifyLayoutAttributes cellAttributes return allAttributesInRect eBookFrenzy com Purchase the fully updated iOS 9 Swift 2 Xcode 7 edition of this book in eBook 12 99 or Print 39 99 format iOS 9 App Development Essentials Print and eBook ePub PDF Kindle edition contains 105 chapters Implementing the modifyLayoutAttributes Method By far the most interesting method to be implemented is the modifyLayoutAttributes method This is where the layout attributes for the cell the user is currently manipulating on the screen are modified This method should now be implemented as outlined in the following listing void modifyLayoutAttributes UICollectionViewLayoutAttributes layoutAttributes If the indexPath matches the one we have stored if layoutAttributes indexPath isEqual currentCellPath Assign the new layout attributes layoutAttributes transform3D CATransform3DMakeScale currentCellScale currentCellScale 1 0 layoutAttributes center currentCellCenter layoutAttributes zIndex 1 In completing the example application a pinch gesture recognizer will be attached to the collection view object and configured to set the currentCellPath currentCellScale and currentCellCenter values of the layout object in real time as the user pinches and moves a cell As is evident from the above code use is made of these settings during the attribute modification process Since this method will be called for each cell in the collection it is important that the attribute modifications only be applied to the cell the user is currently moving and pinching This cell is stored in the currentCellPath property as updated by the gesture recognizer if layoutAttributes indexPath isEqual currentCellPath If the cell matches that referenced by the currentCellPath property the attributes are transformed via a call to the CATransform3DMakeScale function of the QuartzCore Framework using the currentCellScale property value which is updated by the gesture recognizer during a pinching motion layoutAttributes transform3D CATransform3DMakeScale currentCellScale currentCellScale 1 0 Finally the center location of the cell is set to the currentCellCenter property value and the zIndex property set to 1 so that the cell appears on top of overlapping collection view contents The implementation of a custom collection layout is now complete All that remains is to implement the gesture recognizer in the application code so that the flow layout knows which cell is being pinched and moved and by how much Adding the New Layout and

    Original URL path: http://www.techotopia.com/index.php/Subclassing_and_Extending_the_iOS_7_Collection_View_Flow_Layout (2016-02-13)
    Open archived version from archive



  •